would you please suggest me what is the best way to add multiple components into a table's cell ( button,textfield, jlabel and icon ..)
should I define a jpanel that contains these components and insert this jpanel into the cell by defining a new renderer.
please see the photo
waiting for your suggestions ... if possible some few lines of code as an example
thank you very much
Samer Telawi wrote:should I define a jpanel that contains these components and insert this jpanel into the cell by defining a new renderer.
In a general way, yes.
Note that the corresponding slot in your table model should not contain Swing components, but rather an object of a class that encapsulates the state that is to be represented in the table cell. The custom renderer will then cast the value parameter to this class and extract the information for display.
There are no new questions, but there may be new answers.
Give an object of that class as the cell renderer of the corresponding cell.
There's no call to extendJPanel. The class can contain a JPanel field. Favor composition over inheritance.
And the primary advantage of using a renderer is lost if a new JPanel is constructed for each get...RendererComponent(...) call. You should update the state to provide the desired visual representation of the value parameter and return the same instance.
and the problems are like the following:
1- sometimes when I run this code I get the table but the second column is empty, and I should do some action like resizing or clicking to show the components in the second column as photo number 1 shows.
2- when I click on the left column everything is ok and the complete row is selected, but when I click on the second column (the right one) just the right column is selected and the current one becomes white and all components disappear. beside when I click on the button sometimes the same scenario happens and the color of the button does not change when I click another one. it is shown in photo number 2
would you please check the code for me and tell what to do ... I believe there is something missing ...