当我想要关闭某个框架并打开那些在JTable
里面生成的框架时,我有问题。在控制台中出现了很多错误。当我想要关闭并打开另一个框架而不是JTable
时,我的代码可以正常工作。
我以这种方式创建表:
public table(){
setLayout(new FlowLayout());
String [] kolumny={"name of columns"};
Object [][] dane ={
{"","","","",""},
{"","","","",""},
};
table=new JTable(dane,kolumny);
table.setPreferredScrollableViewportSize(new Dimension(500,50));
table.setFillsViewportHeight(true);
JScrollPane scrollPane = new JScrollPane(table);
add(scrollPane);
table qui = new table();
qui.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
qui.setSize(500,500);
qui.setVisible(true);
qui.setTitle("Tabela");
关闭并打开另一帧的代码:
JMenuItem jakas nazwa = new JMenuItem("jakas nazwa");
akcja.add(jakas nazwa);
jakas nazwa.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
new qui().setVisible(true);
Nazwa okienka które zamykamy.this.dispose();
}
});
一些错误:
Exception in thread "AWT-EventQueue-0" java.lang.StackOverflowError
at sun.awt.SunToolkit.isInstanceOf(Unknown Source)
at sun.awt.SunToolkit.isInstanceOf(Unknown Source)
at sun.awt.SunToolkit.isInstanceOf(Unknown Source)
at sun.awt.SunToolkit.isInstanceOf(Unknown Source)
at sun.awt.SunToolkit.isInstanceOf(Unknown Source)
at sun.awt.SunToolkit.isInstanceOf(Unknown Source)
at sun.awt.SunToolkit.isInstanceOf(Unknown Source)
at sun.awt.SunToolkit.isInstanceOf(Unknown Source)
at javax.swing.LookAndFeel.installProperty(Unknown Source)
at javax.swing.plaf.basic.BasicButtonUI.installDefaults(Unknown Source)
at javax.swing.plaf.metal.MetalButtonUI.installDefaults(Unknown Source)
答案 0 :(得分:1)
您正在table
构造函数中创建新的table
。这就是你获得stackoverflow
的原因。这是一个无限循环。
拿出来:
table qui = new table();
只需使用此
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setSize(500,500);
setVisible(true);
setTitle("Tabela");
备注:使用Java命名约定。课程以大写字母开头