Answer the question
In order to leave comments, you need to log in
How to create a table in Java Swing GUI?
Good day. I have been tormenting myself for an hour over the problem: it is necessary to create an interface in which JTable will be included. I threw a form in the GUI that is in the IDE. And I added a model to the table from the GUI, but for some reason it is not displayed if I add the entire Frame via JFrame.add. But if you add a separate table, then it is displayed.
MainForm.java
public class MainForm extends JFrame{
private JPanel mainPanel;
private JPanel leftPanel;
private JPanel rightPanel;
private JLabel middleResult;
private JTextPane textPane1;
private JLabel items;
private JTable table1;
private JTable table2;
private JTable table3;
private JButton считатьButton;
private JButton очиститьButton;
private JButton выходButton;
private JScrollPane ScrollPane;
public MainForm() {
//Отрисовыаем окно
setTitle("Transport Task");
setSize(new Dimension(700, 500));
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ItemsTableModel itm = new ItemsTableModel();
table1 = new JTable(itm);
ScrollPane = new JScrollPane(table1);
add(mainPanel);
setVisible(true);
}
}
import javax.swing.*;
import java.awt.*;
/**
* Created by muffass on 09.10.15.
*/
public class MainForm extends JFrame{
private JPanel mainPanel;
private JPanel leftPanel;
private JPanel rightPanel;
private JLabel middleResult;
private JTextPane textPane1;
private JLabel items;
private JTable table1;
private JTable table2;
private JTable table3;
private JButton считатьButton;
private JButton очиститьButton;
private JButton выходButton;
private JScrollPane ScrollPane;
public MainForm() {
//Отрисовыаем окно
setTitle("Transport Task");
setSize(new Dimension(700, 500));
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ItemsTableModel itm = new ItemsTableModel();
table1 = new JTable(itm);
ScrollPane = new JScrollPane(table1);
add(ScrollPane);
setVisible(true);
}
}
Answer the question
In order to leave comments, you need to log in
I would advise you to start working with JavaFX already, especially since you do not have a complicated graphical interface
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question