简体   繁体   English

单击JFrame中的JPanel

[英]clicking a JPanel inside a JFrame

So I have a JFrame , in which it has a bunch of JPanel which is called venPanel . 所以我有一个JFrame ,它有一堆叫做venPanelJPanel 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). 当我点击一个venPanel我希望JFrame在布局的东边添加一个新的JPanel (因为JFrame使用边框布局)。 How can I achieve this in my venPanel class? 我如何在我的venPanel课程中实现这一venPanel Currently the mouseClick action listener for the venPanel is implemented as: 目前, venPanelmouseClick动作侦听器实现为:

@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.. GUIVenDetailsJPanel ,我想添加到东边JFrame 。我希望这个问题是清楚的..

Something like: 就像是:

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

或者您可以向使用CardLayout的EAST添加JPanel ,然后通过调用CardLayout方法在该位置交换JPanels

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM