Is there a way to keep the first column of a JTable embedded inside a JScrollPane static on scrolling the mouse horizontally.The table contains more than 50 columns.
There is an example of this on this Swing examples site. The author creates two tables, putting one of them in the scrollpane. They both share the same model. He then ties their selection logic together. The full code is available on the page.
Related
So Suppose I create a JTable with a specific number of columns and rows. Is it possible to add a JPanel to a specific cell after the JTable is already initialized? The JTable would be empty at first and then I would change a cell at row X and column Y to instead contain a JPanel which would contain an amount of ImageIcons. I don't have any code to put here really, I just need to know what I would have to use to accomplish this and how. Thank you.
To change the data in the table you use:
table.setValueAt(...);
This will update the data in the TableModel.
However, adding a JPanel to the table is not the way a table is designed to be used. Typically you add data to the model. Then you use a renderer to display the data in a cell.
Start by reading the section from the Swing tutorial on Using Custom Renderers for more information and examples.
I have a GUI with a few JTextFields and JTables, and I would like to get the possibility to dynamically re-size the tables after running the application, so the user can increase the size of the tables by clicking on the border and dragging it.
I am considering this option or this post, but not sure if that´s what I need.
JTables are combined with table scrollers, and the GUI uses a JPanel with JGoodiesFormLayout, since it makes very easy to work with rows and columns.
Use JSplitPanes to divide the GUI where you want to allow the user to specify the component limits.
I would like to create a Table something like this:
I hope the picture is good enough. If a scrollpane is activated only the cells shall move and header and subheader keep to stay at their place. How do I do this with JList or JTable? Or is there another component? Thanks a lot
easier and possible by using JTable, rather than JList, see RowHeader
based on #camickrs Row Number Table
One approach could be to have 3 different tables.
For the header to stay in place when you scroll the cells, you can create 2 tables. One will contain only the header (without cells) and would be in the north position of a border layout in a JPanel. In the center position of the JPanel you would add a JScrollPane with a table and you would need to remove the header for it, so that the displayed header for the table would be the one of the table in the north position.
For the "subheader" you would need another table, with only one column and a header renderer added to that column. That table should be in the west position of the JPanel.
Finally you would need to synchronise the header of the north table with the columns of the center's one, so when it is resized the columns of the other are as well. If the table is sortable you would need to do the same with the table in the west position.
A better option can be to use TableScrollPane from JIDESoft, that does all this and more behind the scenes, but is paid.
Your choice.
I have to develop a front end in Swing.I have a JFrame in Netbeans with 3 panes in it.
JScrollPane 1:it contains a JTable
JScrollPane 2: It should display the value of the fields of the selected row
ListPane : which contains the list of tables from which a user chooses a table to be displayed.
Now since the content of JTable varies(the no of rows and columns also vary) dynamically based on the table chosen by user I can't drag and drop the TextBoxes in the 3rd scroll pane to display the selected row's values.It would be helpful if anybody can suggest a way to do it or any pointers to problems that deal with similar issue
Add a ListSelectionListener to your JList. When a particular table is selected from the list, use setModel() to change the TableModel of your JTable to one that is correct for the chosen table. A related example using setModel() is shown here.
I would like to create an interactive JTable. For this, I would like to add JPanels in the cells of the table. Once the JPanels are in the cells, I can add my various components to the JPanels thus making the table interactive. Each JPanel could have different components. Would it be possible to accomplish this and only have to create 1 table cell editor and 1 table cell tenderer. Does anyone know of a better way to do it?
Thanks
EDIT: Thanks for the responses. I actually already have a framework I am using. I just needed a JTable that users could drag and drop images in, play movies, display graphs, etc... I already have the functionality to do those things, I just needed a JPanel to add them too. I wanted it to be displayed in a JTable so the cells could be sorted, moved, add/delete rows/col, and well structured. I couldn't get it to work using the JTable, so I went ahead an created my own. Its just a JPanel that contains smaller JPanels (the table cells) using the GridLayout. It works well enough for my puposes. Just a pain to rewrite all of the functionality from scratch that a table has.
This is hard. JTable actually uses the cell renderers only for painting the cell content. I would recommend to check if a gridlayout packaged into a scrollpane would be the easier solution.
It sounds like you're trying to use JTable as a docking framework. Assuming this is the case you're better off using something like MyDoggy or JDock which allow you to decompose your GUI into multiple split pane areas.
JSplitPane may be an alternative in this context: one pane would hold the JTable, while the other displays expanded details of the selected row. A compete example using GridLayout is shown here.