JInternalFrame点击了按钮事件以后不显示

断剑问苍天 2016-08-03 02:29:18
我有3个类,一个主窗体类,一个事件类,还有一个是JInternalFrame的类,我的想法是点击按钮之后,就new出一个JInternalFrame的实体添加到主窗体类里面,但是不显示,也不报错。。下面的代码省略了一部分。。不然太多了。
public class IndexJFrame extends JFrame{
public JDesktopPane jDesktopPane;
public IndexJFrame(){
jDesktopPane=new JDesktopPane();
jDesktopPane.setBackground(Color.white);
container.add(jDesktopPane,BorderLayout.CENTER);
}

//主界面事件类
public class IndexListener implements ActionListener,WindowListener,TreeSelectionListener{
IndexJFrame indexJFrame;
TreePath path;
@Override
public void actionPerformed(ActionEvent e) {
JButton button=(JButton) e.getSource();
if (button==indexJFrame.jButtonDA) {
indexJFrame.remove(indexJFrame.rightpanel);// 移除内容面板中的所有内容
indexJFrame.jDesktopPane.add(new TestJpanel(),BorderLayout.CENTER);// 将档案管理面版添加到内容面板中
SwingUtilities.updateComponentTreeUI(indexJFrame.rightpanel);// 刷新内容面板中的内容
}
}

public class TestJpanel extends JInternalFrame{
public TestJpanel(){
JLabel jLabel=new JLabel("测试测试测试测试测试测试测试测试测试测试");


JInternalFrame jInternalFrame=new JInternalFrame("yoo", true, true, true);
jInternalFrame.setSize(400, 400);
jInternalFrame.setLocation(5, 5);
jInternalFrame.setLayout(null);
jLabel.setBounds(5, 5, 100, 25);
Container container=jInternalFrame.getContentPane();
container.add(jLabel);
jInternalFrame.setVisible(true);

}
}
...全文
257 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
断剑问苍天 2016-08-03
  • 打赏
  • 举报
回复
自己解决了。、。。
NewMoons 2016-08-03
  • 打赏
  • 举报
回复
楼主你的代码精简过了,有报错,无法帮你拍错。 第一个类的【container.add(jDesktopPane,BorderLayout.CENTER);】 container没有定义的地方。

62,626

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧