I always have a window that I want to leave above all other windows. Using setAlwaysOnTop (true) seems to work for most purposes, but doesn't work when it comes to the JComboBox dropdown menu. Is there any way to prevent this? SSCCE and image of undesirable functionality are attached below.
EDIT: Not sure if the behavior is OS dependent, but I notice a problem in Windows 7 using Java 7. The top of this OS is supported.
EDIT 2: It seems that JPopupMenu has an override on alwaysOnTop () to return true. This is the source of the problem, because the top components do not have a specific order in how they appear on top of each other (OS dependent). Even worse, this method is a private package. Very problematic ...
Unwanted behavior:

SSCCE:
import java.awt.BorderLayout;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JTextField;
public class OnTopTest
{
public static void main( String[] args )
{
new OnTopTest();
}
public OnTopTest()
{
JDialog onTop = new OnTopWindow();
JDialog other = new OtherWindow();
System.out.println("IS ON TOP SUPPORTED? " + onTop.isAlwaysOnTopSupported());
other.setVisible( true );
onTop.setVisible( true );
}
private class OnTopWindow extends JDialog
{
public OnTopWindow()
{
setLayout( new BorderLayout() );
JButton button = new JButton("Button");
add( button, BorderLayout.CENTER );
setSize( 100, 100 );
setAlwaysOnTop( true );
}
}
private class OtherWindow extends JDialog
{
public OtherWindow()
{
setLayout( new BorderLayout() );
JTextField textField = new JTextField("Text");
add( textField, BorderLayout.NORTH);
JButton button = new JButton("Button");
add( button, BorderLayout.CENTER );
JComboBox comboBox = new JComboBox( new Object[] {"Item1", "Item2", "Item3"} );
add( comboBox, BorderLayout.SOUTH );
setSize( 200, 200 );
}
}
}
source
share