0

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();
}
mKorbel
  • 109,525
  • 20
  • 134
  • 319
BlackEye
  • 775
  • 11
  • 25
  • The problem was the `public void userSignedIn(User user) { removeAll();` Can someone explain why exactly this causes the given situation? – BlackEye May 14 '13 at 11:51

1 Answers1

1

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
mKorbel
  • 109,525
  • 20
  • 134
  • 319