Answer the question
In order to leave comments, you need to log in
Why are column names not displayed in JTable?
static String[] headers = { "Name", "Surname", "Telephone" };
static String[][] data = {
{ "John", "Smith", "1112221" },
{ "Ivan", "Black", "2221111" },
{ "George", "White", "3334444" },
{ "Bolvan", "Black", "2235111" },
{ "Serg", "Black", "2221511" },
{ "Pussy", "Black", "2221111" },
{ "Tonya", "Red", "2121111" },
{ "Elise", "Green", "2321111" },
};
static JTable myTable;
myTable = new JTable(data, headers);
frame.add(myTable);
Answer the question
In order to leave comments, you need to log in
Add
myTable.setFillsViewportHeight(true);
JScrollPane scrollPane = new JScrollPane(myTable);
public class MyTable {
public static String[] headers = { "Name", "Surname", "Telephone" };
public static Object[][] data = {
{ "John", "Smith", "1112221" },
{ "Ivan", "Black", "2221111" },
{ "George", "White", "3334444" },
{ "Bolvan", "Black", "2235111" },
{ "Serg", "Black", "2221511" },
{ "Pussy", "Black", "2221111" },
{ "Tonya", "Red", "2121111" },
{ "Elise", "Green", "2321111" },
};
public static JTable myTable;
public MyTable() {
myTable = new JTable(data, headers);
myTable.setFillsViewportHeight(true);
JScrollPane scrollPane = new JScrollPane(myTable);
JFrame frame = new JFrame();
frame.add(scrollPane);
frame.pack();
frame.setVisible(true);
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question