[ Back | Previous | Next ]

How to keep a frame/dialog always on top?

Package:
javax.swing.*
Product:
Swing
Release:
1.0.3
Related Links:
ComboBox
JDialog
JFileChooser
JFrame
JOptionPane
JProgressBar
JScrollPane
JTable
General
JTree
JWindow
KeyStroke
LayeredPane
UIDefaults
Comment:
One way is to monitor the 'deactivated' event.
 Whenever the window is deactivated bring it back ( toFront( ) )
  
 I do this with a dialog, seems to be working.

class IvjEventHandler implements java.awt.event.ActionListener, java.awt.event.WindowListener {
		public void actionPerformed(java.awt.event.ActionEvent e) {
			if (e.getSource() == AbstractSearchPanel.this.getZoekButton()) 
				getZoekFrame().toFront();
		};
		public void windowActivated(java.awt.event.WindowEvent e) {};
		public void windowClosed(java.awt.event.WindowEvent e) {};
		public void windowClosing(java.awt.event.WindowEvent e) {};
		public void windowDeactivated(java.awt.event.WindowEvent e) {
			if (e.getSource() == AbstractSearchPanel.this.getZoekFrame()) 
				connEtoC1(e);
		};
		public void windowDeiconified(java.awt.event.WindowEvent e) {};
		public void windowIconified(java.awt.event.WindowEvent e) {};
		public void windowOpened(java.awt.event.WindowEvent e) {};
	};
}

/**
 * Return the JDialog1 property value.
 * @return javax.swing.JDialog
 */
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private javax.swing.JDialog getZoekFrame() {
	if (ivjZoekFrame == null) {
		try {
			ivjZoekFrame = new javax.swing.JDialog();
			ivjZoekFrame.setName("ZoekFrame");
			ivjZoekFrame.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
			ivjZoekFrame.setBounds(58, 162, 534, 240);
			ivjZoekFrame.setModal(true);
			ivjZoekFrame.setTitle(resHavenPanelRes.getString("titel.zoekpaneel"));
			getZoekFrame().setContentPane(getJDialogContentPane());
			// user code begin {1}
   getZoekFrame().addWindowListener( new IvjventHandler());
			// user code end
		} catch (java.lang.Throwable ivjExc) {
			// user code begin {2}
			// user code end
			handleException(ivjExc);
		}
	}
	return ivjZoekFrame;
}
1