clicking a JPanel inside a JFrame
So I have a JFrame
, in which it has a bunch of JPanel
which is called venPanel
. When I click on a venPanel
I want the JFrame
to add a new JPanel
to the east of the layout (because the JFrame
uses the border layout). How can I achieve this in my venPanel
class? Currently the mouseClick
action listener for the venPanel
is implemented as:
@Override
public void mouseClicked(MouseEvent arg0) {
try {
GUIVenDetails vendetail = new GUIVenDetails(ven);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTr开发者_StackOverflow社区ace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Where GUIVenDetails
is the JPanel
I wanted to add to the east of the JFrame
..
I hope the question is clear..
Or you could add a JPanel
to the EAST that uses a CardLayout
and then swap JPanels
in that spot by calling the CardLayout
methods.
Something like:
JPanel source = (JPanel)event.getSource();
JPanel parent = (JPanel)source.getParent();
parent.add(anotherPanel, BorderLayout.EAST);
parent.revalidate();
精彩评论