1

Is it possible to use a Dialogtitle-button with switchcase or something else to turn on/off the visibility of a framelayout?

Or should I use any other method? I just want to use that button as a switch, when press it makes the framelayout visible and once again it will become invisible and so forth..

For the first press:

timerLayout.setVisibility(View.VISIBLE);

For the second press:

timerLayout.setVisibility(View.INVISIBLE);

Thanks in advance! :)

hata
  • 11,633
  • 6
  • 46
  • 69
Davvarn
  • 101
  • 1
  • 1
  • 2

1 Answers1

0

You can just reverse the current status:

timerLayout.setVisibility(!timerLayout.isVisible());

But you should be aware that SWING is not thread save, therefore you should use invokeLater (See: SwingUtilities.invokeLater() why is it needed?)

So your final code could look something like this:

yourButton.addActionListener(new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                timerLayout.setVisibility(!timerLayout.isVisible());
            }
        });
    }
});
Community
  • 1
  • 1
Xavjer
  • 8,838
  • 2
  • 22
  • 42