所以我以intellij的形式创建了一个gui,当我取出与表有关的代码时,它确实是我想要的,但是当我将所有代码放入表中时,便得到了表本身。我在使用gui表单本身添加列时遇到了麻烦,并找到了一个教程,展示如何使用代码添加列等。我如何能够向表中添加行和/或将表置于表单上
public class App extends JFrame{
private JButton createRecordButton;
private JPanel panel1;
private JPanel east;
private JPanel west;
private JPanel south;
private JButton deleteRecordButton;
private JButton viewStatisticsButton;
private JButton downloadDataButton;
public JTable TestDB;
public App() {
}
public static void main(String[] args) {
JFrame frame=new JFrame("App");
frame.setContentPane(new App().panel1);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
table gui=new table();
gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
gui.setSize(600,200);
gui.setVisible(true);
gui.setTitle("The DataBase Table");
}
}
答案 0 :(得分:0)
您正在以下行中生成异常:frame.setContentPane(new App()。panel1); 请注意,您创建了App对象,但是panel1对象仍然为null。 使用此代码,您将看到两个JFrame都将出现:
public class App extends JFrame{
private JButton createRecordButton;
private JPanel panel1;
private JPanel east;
private JPanel west;
private JPanel south;
private JButton deleteRecordButton;
private JButton viewStatisticsButton;
private JButton downloadDataButton;
public JTable TestDB;
public App() {
panel1 = new JPanel();
}
public static void main(String[] args) {
JFrame frame=new JFrame("App");
frame.setContentPane(new App().panel1);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
JFrame gui=new JFrame();
gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
gui.setSize(600,200);
gui.setVisible(true);
gui.setTitle("The DataBase Table");
}
}