aherlambang
aherlambang

Reputation: 14418

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.printStackTrace();
    } 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..

Upvotes: 1

Views: 831

Answers (2)

Hovercraft Full Of Eels
Hovercraft Full Of Eels

Reputation: 285401

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.

Upvotes: 3

camickr
camickr

Reputation: 324108

Something like:

JPanel source = (JPanel)event.getSource();
JPanel parent = (JPanel)source.getParent();
parent.add(anotherPanel, BorderLayout.EAST);
parent.revalidate();

Upvotes: 2

Related Questions