Swing - Swapping and hiding glass pane does not work - glass pane remains visible

I am trying to build a Swing application that shows a login panel as a glasspane if no user is loggeg in. If i try to hide to login glass pane it remains visible, but won't react to any user interactions.

Do you see any problems here?

public class HauptFrame implements SessionListener {

private static final long serialVersionUID = 7985854311368619704L;

public HauptFrame() {
    initialize();
}

public void initialize() {
    Session.get().addSessionListener(this);
    setSize(1024, 768);
    setVisible(true);
    startAndCheck();
}

public void startAndCheck() {
    if (!DatabaseManager.doesConfigExist()) {
        setNewGlassPane(new SetupGlassPanel(this));
    }
    else if (new UserDAO().getAllUser().size() == 0) {
        setNewGlassPane(new FirstUserGlassPane(this));
    }
    else if (Session.get().getUser() == null) {
        setNewGlassPane(new LoginGlassPanel());
    } else {
        setNewGlassPane(null);
    }
}

public void setNewGlassPane(JPanel glassPane) {
    if (glassPane != null) {
        getGlassPane().setVisible(false);
        setGlassPane(glassPane);
        getGlassPane().setVisible(true);
    }
    else {
        if (getGlassPane().isVisible()) {
            getGlassPane().setVisible(false);
        }
    }
}

@Override
public void userSignedIn(User user) {
    removeAll();
    startAndCheck();
}

@Override
public void userSignedOff() {
    startAndCheck();
}

Answers


Do you see any problems here?

  • GlassPane doesn't consume KeyEvents
  • have to add KeyListener to JComponent added to GlassPane, and to override consume()
  • MouseEvents are consumed only in the area that covering JPanel or another JComponent, top component on hierarchy
  • add JLabel (transparent by default) that covering whore RootPane area, add proper LayoutManager to JLabel, then there put JPanel or ....
  • invoke GlassPane from JFrame.getRootPane

Need Your Help

How can my java applet use my PHP authenticated session?

java php http session applet

I have set up a login area on my PHP server. The members.php file requires login; after I login a session is created. The session lasts for a while. I want to make this work so that while the sessi...

Flex LineSeries - find y-value along curve

flex graph interpolation

I've created a Flex LineChart that shows high and low tide predictions over time. I'm using the LineSeries with form="curve", which produces a nice sinusoidal wave graph, representing water level ...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.