In this section, you will learn how to share a table model between JTable components. Whenever, you want to do for sharing the resources between the JTable components, a table model will essential. To share the table model between two table components means sharing all resources to each other. When you change the values in the table model, it will be changed in both the table components. But any changes in the visible columns of one table component can not affect the columns of other table component.
Description of program:
This program helps you to do for sharing a table model between JTable components. For this, first of all you will need two tables that are joint with the same table model. Both the tables have some data and columns with column headers. In this program, you must have to use the JSplitPane that is used to divide two components. These components are graphically divided that are based on look and feel implementation and resized by the user. Here the two components are split in left to right using the HORIZONTAL_SPLIT. Both components are added in the object of JSplitPane and it is also added in the frame's panel. Finally, both components attaches in the frame. If you want to change in any component, there will be same changes in both the tables. But if any component is removed or added in any table, there will be no changes in any table.
Description of code:
This is the constructor of JSplitPane class that creates a new JSplitPane and arranged the components like: horizontal and vertical. The HORIZONTAL_SPLIT means arrange the components from left to right and VERTICAL_SPLIT arranges from top to bottom.
This is a static integer type that splits the components on the x - axis.
Here is the code of program:
Output of program:
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.