Java --How to make JTable

Way of thinking

  1. Create an initial data structure (columns and data)
  2. Create DefaultTableModel
  3. Create JTable
  4. Put in JScrollPane
  5. Put in JFrame
  6. Draw

Sample code

1, create a data structure

String[] columnNames = { "1", "2", "3", "4" };

String[] data1 = { "A", "B", "C", "D" };
String[] data2 = { "E", "F", "G", "H" };
String[] data3 = { "I", "J", "K", "L" };
String[] data4 = { "M", "N", "O", "P" };
String[] data5 = { "Q", "R", "S", "T" };

String[][] data = { data1, data2, data3, data4, data5 };

2, Create DefaultTableModel

DefaultTableModel model = new DefaultTableModel(data, columnNames);

3, Create JTable

JTable table = new JTable(model);

4, put in JScrollPane

JScrollPane spane = new JScrollPane(table);

5, put in JFrame

JFrame frame = new JFrame("Title");
frame.setSize(500, 500);
frame.add(spane);

6, draw

frame.setVisible(true);

Recommended Posts

Java --How to make JTable
How to make a Java container
How to make a Java array
How to make a Discord bot (Java)
How to make shaded-jar
[Java] How to make multiple for loops single
[Java] How to use Map
How to lower java version
[Java] How to use Map
How to uninstall Java 8 (Mac)
How to use java Optional
How to minimize Java images
How to write java comments
How to use java class
[Java] How to use Optional ②
[Java] How to use removeAll ()
[Java] How to display Wingdings
[Java] How to use string.format
How to use Java Map
How to set Java constants
How to use Java variables
How to convert Java radix
[Rails] How to make seed
[Java] How to implement multithreading
[Java] How to use Optional ①
How to initialize Java array
How to make Java unit tests (JUnit & Mockito & PowerMock)
How to study Java Silver SE 8
How to use Java HttpClient (Get)
Studying Java # 6 (How to write blocks)
[Java] How to update Java on Windows
How to disassemble Java class files
How to use Java HttpClient (Post)
[Java] How to use join method
How to make a JDBC driver
How to learn JAVA in 7 days
[Processing × Java] How to use variables
[Java] How to create a folder
How to decompile java class files
[Java] How to use LinkedHashMap class
[JavaFX] [Java8] How to use GridPane
How to write Java variable declaration
How to make a splash screen
How to make a Jenkins plugin
How to use class methods [Java]
[Java] How to use List [ArrayList]
How to use classes in Java?
How to make a Maven project
How to name variables in Java
How to pass Oracle Java Silver
How to turn Iterator Dojo (Java)
java Eclipse How to debug javaScript
[Processing × Java] How to use arrays
How to use Java lambda expressions
[Android] How to make Dialog Fragment
[Java] How to use Math class
How to find Java prime numbers
How to use Java enum type
How to concatenate strings in java
How to check Java installed on Mac
How to implement date calculation in Java