`
liuwangxia
  • 浏览: 137678 次
  • 性别: Icon_minigender_1
  • 来自: 黄石
社区版块
存档分类
最新评论

Implements a semi-modal JInternalFrame

    博客分类:
  • Java
阅读更多
参考下面的 links,做了一个 semi-modal JInternalFrame:
Creating Modal Internal Frames -- Approach 1 and Approach 2
Java GUI - Make JInternalFrame behave like modal dialog
Java Technology Forums - Modal Internal Frames and JCombos

import java.beans.*;

import javax.swing.*;

public class JXFrame extends JFrame implements VetoableChangeListener {
	public void vetoableChange(PropertyChangeEvent evt)
			throws PropertyVetoException {
		if (evt.getPropertyName().equals(JXInternalFrame.IS_SELECTED_PROPERTY)) {
			if(evt.getSource() instanceof JXInternalFrame) {
				JXInternalFrame frame = (JXInternalFrame)evt.getSource();
				frame.selectChild();
			}
			throw new PropertyVetoException("Selected", null);
		}
	}
}


import java.awt.*;
import java.awt.event.*;
import java.beans.*;

import javax.swing.*;
import javax.swing.event.*;

public class JXInternalFrame extends JInternalFrame {
	private boolean modal = false;

	private JXInternalFrame parent = null;

	private JXInternalFrame child = null;

	private static JXFrame desktopFrame = null;

	private Component originalGlassPane;

	private GalssPaneForModal modalGlassPane;

	private Integer defaultCloseOperation = null;

	public JXInternalFrame() {
		super();
	}

	public JXInternalFrame(String title) {
		super(title, true, true, true, true);
	}

	public JXInternalFrame(JXInternalFrame parent, boolean modal, String title) {
		super(title, true, true, true, true);
		this.parent = parent;
		if (modal) {
			startModal();
		}
	}

	public JXInternalFrame(String title, boolean resizable) {
		super(title, resizable);
	}

	public JXInternalFrame(String title, boolean resizable, boolean closable) {
		super(title, resizable, closable);
	}

	public JXInternalFrame(String title, boolean resizable, boolean closable,
			boolean maximizable) {
		super(title, resizable, closable, maximizable);
	}

	public JXInternalFrame(String title, boolean resizable, boolean closable,
			boolean maximizable, boolean iconifiable) {
		super(title, resizable, closable, maximizable, iconifiable);
	}

	public boolean isModal() {
		return modal;
	}

	public void startModal() {
		if (!modal && parent != null && desktopFrame != null) {
			parent.setChild(this);
			originalGlassPane = parent.getGlassPane();
			modalGlassPane = new GalssPaneForModal();
			modalGlassPane.containerFrame = parent;
			parent.setGlassPane(modalGlassPane);
			parent.addVetoableChangeListener(desktopFrame);
			defaultCloseOperation = parent.getDefaultCloseOperation();
			parent.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
			modal = true;
		}
	}

	public void stopModal() {
		if (modal && parent != null && desktopFrame != null) {
			parent.setGlassPane(originalGlassPane);
			parent.removeVetoableChangeListener(desktopFrame);
			if (defaultCloseOperation != null) {
				parent.setDefaultCloseOperation(defaultCloseOperation);
			}
			try {
				parent.setSelected(true);
				if(parent.isIcon)
					parent.setIcon(false);
			} catch (PropertyVetoException e) {
				// TODO: handle exception
			}
			modal = false;
		}
	}

	public void setVisible(boolean visible) {
		super.setVisible(visible);
		if (!visible) {
			stopModal();
		}
	}

	public static void setDesktopFrame(JXFrame desktopFrame) {
		JXInternalFrame.desktopFrame = desktopFrame;
	}

	public JXInternalFrame getChild() {
		return child;
	}

	public void setChild(JXInternalFrame child) {
		this.child = child;
	}

	public void selectChild() {
		JXInternalFrame child = this;
		while(child.getChild() != null)
			child = child.getChild();
		try {
			child.setSelected(true);
		} catch (PropertyVetoException exception) {
			// TODO: handle exception
		}
	}
}

class GalssPaneForModal extends JComponent {
	JXInternalFrame containerFrame = null;

	public void setVisible(boolean visible) {
		super.setVisible(true);
	}

	public GalssPaneForModal() {

		this.setOpaque(false);
		MouseInputAdapter listener = new MouseInputAdapter() {
			@Override
			public void mousePressed(MouseEvent e) {
				containerFrame.selectChild();
			}
		};
		addMouseListener(listener);
		addMouseMotionListener(listener);
	}
}
分享到:
评论

相关推荐

    PyPI 官网下载 | protocol_implements_decorator-0.3.1.tar.gz

    标题中的"PyPI 官网下载 | protocol_implements_decorator-0.3.1.tar.gz"表明这是一个在Python Package Index(PyPI)上发布的软件包,名为`protocol_implements_decorator`,版本为0.3.1,且以tar.gz格式打包。...

    python代码实现飞机大战The-Python-code-implements-aircraft-warfare.zi.zip

    五子棋游戏想必大家都非常熟悉,游戏规则十分简单。游戏开始后,玩家在游戏设置中选择人机对战,则系统执黑棋,玩家自己执白棋。双方轮流下一棋,先将横、竖或斜线的5个或5个以上同色棋子连成不间断的一排者为胜。...

    Provide-a-RectangleDoubler-class-that-implements-the-Doubler-interface

    throw new IllegalArgumentException("Provided object is not a Rectangle"); } } // 其他辅助方法,如设置长度和宽度 } ``` 在这个实现中,`RectangleDoubler`类通过`@Override`注解标记`doubleArea()`方法...

    SHA-256-Matlab-Implements SHA-256 Algorithm.zip

    这个压缩包"SHA-256-Matlab-Implements SHA-256 Algorithm.zip"包含了相关的MATLAB代码,用于实现SHA-256算法。 SHA-256算法的工作原理是将任意长度的输入(也称为预映射)通过一系列复杂的数学和逻辑运算,转换成...

    A-program-that-simultaneously-implements-face-detection-and-human-skeleton-extraction:同时实现人脸检测和人体骨骼提取的程序

    同时实现面部检测和人体骨骼提取的程序同时实现人脸检测和人体骨骼提取的程序作者:电子邮件: 或介绍我编写了一个程序,可以同时执行面部检测和人体骨骼提取。 人脸检测基于Dlib库和OpenCV库。...

    Ariane/cva6源码

    CVA6 is a 6-stage, single issue, in-order CPU which implements the 64-bit RISC-V instruction set. It fully implements I, M, A and C extensions as specified in Volume I: User-Level ISA V 2.3 as well as...

    mybatis-generator-core-1.4.0-SNAPSHOT.jar

    mybatis-generator-core-1.4.0-SNAPSHOT. 源码生成mybatis-generator-core-1.4.0-SNAPSHOT.jar方法.详细可见 https://blog.csdn.net/dono118/article/details/82980841

    Android代码-LocalGsmNlpBackend

    NOTICE The author of this backend is now primarily focused on the Déjá Vu backend.... This project implements a cell-tower based lookup for your current location. This "GSM Location Backend" wo

    用java写的记事本源码

    - 实现类:`class xianjian implements ActionListener` - 功能描述:清空文本区域的内容。 - 方法实现:`public void actionPerformed(ActionEvent e)`,在触发时清空`JTextArea`对象`ta`的内容。 - **打开功能...

    javaweb-tomcat浏览器聊天室毕业设计

    javaweb-tomcat浏览器聊天室毕业设计 JDBCUtils类会去访问c3p0-config中的配置文件;... return ------UserDaoImple implements UserDao ---------dao.login()//sql语句查询 return existUser;

    proxy_http_connector.rar_http proxy

    A HttpConnector implements a non-HTTP proxied connection through the CONNECT method.

    fdtd1D.zip_MáS_lattice.m_space domain

    This MATLAB M-file implements a finite-difference time-domain solution of Maxwell s curl equations over a one-dimensional space lattice comprised of uniform grid cells.

    DISQLite3 5.5.0 for D4-XE6

    DISQLite3 implements a self-contained, embeddable, zero-configuration SQL database engine for Delphi (Embarcadero / CodeGear / Borland). Features include: ACID transactions, even after system ...

    DISQLite 3.1.3.12 Full source

    DISQLite3 implements a self-contained, embeddable, zero-configuration SQL database engine. Features include: * ACID transactions, even after system crashes and power failures. * Zero-configuration –...

    System.Data.SQLite.DLL 64bit

    64位运行库 SQLite is a in-process library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine.

    双边约束最小二乘优化算法

    BCLS implements a two-metric projected-descent method. At each iteration, a search direction is computed that is a combination of a Newton and a scaled steepest-descent step. Some notable features of...

    DISQLite3 Pro v5.10.0 for D4-XE10 SQLite 轻量级 组件

    DISQLite3 implements a self-contained, embeddable, zero-configuration SQL database engine for Delphi (Embarcadero / CodeGear / Borland). Features include: ACID transactions, even after system ...

    sqlite-3.8.0.2-mingw-x64

    編譯好的sqlite x64版 SQLite is a software library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine.

    DISQLite3 v5.12.0 Professional for Delphi 10 Seattle & 10.1 Berlin

    DISQLite3 implements a self-contained, embeddable, zero-configuration SQL database engine for Delphi (Embarcadero / CodeGear / Borland). ACID transactions, even after system crashes and power ...

    SQLite Syntax

    SQLite Syntax 帮助 SQLite is a small C library that implements a self-contained, embeddable, zero-configuration SQL database engine

Global site tag (gtag.js) - Google Analytics