you can use the
jpanel.remove(component);
Statement and it will remove the component from the JPanel.
sirlink99
Practically a Master Poster
661 posts since Oct 2010
Reputation Points: 45
Solved Threads: 19
Are you certain the statement on line 25 is being executed? (it looks OK to me). It may be a problem with your button numbers; you test for 3 and 1, but here's what the API Java|Doc has to say about getButton()...
The values for button range from zero to indicate the left button of the mouse, one to indicate the middle button if present, and two to indicate the right button.
JamesCherrill
Posting Genius
6,373 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073
if TopLayoutContainer http://download.oracle.com/javase/tutorial/uiswing/components/toplevel.html was already visible
1/ if you want/need to add JComponent(s) to the Container (JPanel, JFrame), then you have call
someContainersName.add(someJComponetsName); //EDIT corect method is add
someContainersName.revalidate();
someContainersName.repaint(); // just in some cases
1/ if you want/need to remove JComponent(s) from the Container (JPanel, JFrame), then you have call
someContainersName.remove(someJComponetsName);
someContainersName.revalidate();
someContainersName.repaint();
my questions:
1/ why set opacities for Swing JButton.setOpaque(false);
2/ why you needed remove some JComponent, if there is possible to call
JButton.setVisible(false);, and in the moment when you'll need that, just set/change some properties for inVisible JButtons, thenafter set that to setVisible(true)
3/ are you sure that something in your line 25 has something to do with remove JButton
mKorbel
Veteran Poster
1,141 posts since Feb 2011
Reputation Points: 480
Solved Threads: 224