[英]clicking a JPanel inside a JFrame
So I have a JFrame
, in which it has a bunch of JPanel
which is called venPanel
. 所以我有一个
JFrame
,它有一堆叫做venPanel
的JPanel
。 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: 目前,
venPanel
的mouseClick
动作侦听器实现为:
@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.. 凡
GUIVenDetails
是JPanel
,我想添加到东边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.