Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Which is an example of jtable in java?


Asked by Royal Ashley on Dec 06, 2021 Java



This article shows a simple example of JTable. The JTable component provided as part of the Swing API in Java is used to display/edit two-dimensional data. This is similar to a spreadsheet. Let us consider some examples. Say that you want to display a list of employees belonging to an organization.
In addition,
The JTable component provided as part of the Swing API in Java is used to display/edit two-dimensional data. This is similar to a spreadsheet. Let us consider some examples. Say that you want to display a list of employees belonging to an organization. This should display the various attributes of employees.
And, All the components in the Swing API follow the MVC paradigm and JTable is no exception. Let us try and understand why this is needed and how this helps us. In simple terms, the Model-View-Controller paradigm dictates that the data be held in a Model.
Indeed,
Each JTable has three models TableModel, TableColumnModel, and ListSelectionModel. TableModel is used to specify how the table’s data is stored and retrieval of this data. JTable’s data is often in two-dimensional structure such as a two-dimension array or a Vector of Vectors.
Consequently,
Coming back to the code, a JTable instance is then created by using the constructor that takes the data and column arrays. Rest of the code is about building the JFrame and adding the JTable instance to the JFrame (the JTable instance is wrapped in a JScrollPane instance to enable scrolling). There are a few problems with this program.