making two tables in the same jScrollPane - java

I want to make many tables in the same pane and show the one I want by clicking on a button by hidding a table and showing the other , the problem is i can't put a table on top of the other in NetBeans. How can i put all tables one above the other?

and show the one I want by clicking on a button by hidding a table and showing the other
Don't attempt to have two tables in the same scrollpane.
If you want to change the component in the scrollpane you would just use:
scrollPane.setViewportView( theOtherTable );
Or you can just change the model of the table:
table.setModel( ... );

Related

Java How To Hide Columns Names In JTable

I dont want to cancel any columns. I just dont want to see column names. So normaly i use the JTable with scroll pane. And i use this code:
scrollPane.setViewportView(table);
But when i use this i cant hide the column names. So i tryed something else and i fine this code:
scrollPane.setColumnHeaderView(table);
This does what i need but when i use this code ,i cant see the all table and there is no scroll bar.
So basicly i want a table with scroll bar and with out columns name. Im sure its easy but i cant find it.

Java create table with a button on the first row

I'm trying to create a table where the first row contains 1 button, and the other rows contain multiple columns. Example picture:
How could I make this?
I've attempted the following: add button to table but that only allows you to add a button like this:
I've looked at other stackOverflow posts, but those answers contain dead links, which are no help to me.
This is relatively easy by placing the button outside the table. Here is how to go about it:
Create a panel with a BorderLayout. Add the table (to a scroll pane) to the CENTER of the border layout. Add the button to the PAGE_START of the border layout. Job done.

JButton inside JTable inside JTable inside JTabbedPane

So the code behind it is quite massive.
I have JTabbedPane with a Tab for each table(inside JSCrollPane ) and a Summary table which contains tables that uses the same models as models in the tabs. So when I add rows to the table everything renders properly. When one of the tables has its data changed everything renders OK , except the JButtons (the button in the first row always renders) . Clicking on the line fixes it , even if it changes again the button does not disappear.
When data changes I only fireDataChanged() for the model of contained tables, the model does fire repaint on the contained tables and the container table.
Each swing component can be in only one container. The problem comes if you try to put into two Jpanels, if you do that with 2 Jtables that use the same instance of a model ,what happens is originally everything renders properly , but will break as soon as you activate the component(button). It will stop rendering in the table where you pressed it , in some cases both.

Get MouseListener results from one class to another Java

I have a class with panelC which contains a table populated with customer info, some textfields and buttons. Then I also have another class panelP which contains almost the same as panelC but with product info. Then in my main class I create a window with a tabbedPane and I add the above panels as tabs. My problem is that whenever I select a row in panelC table the values are transferred in a textfield, but I can't get those values in panelP class.
Any ideas on how to deal with this? :(

Drop down content in JTable

I want to show all the categories in the database in each line of a JTable i have done that. Now when i click on the each row of JTable i need to show the list of products under it (considered as child of the category) as a drop down not as a drop down list which closes automatically when focus is lost, but it should stay there until i click on minimize icon in the same row. It is just like expanding content. so i can expand all categories individually. The working is similar to JTree but i need it in JTable so that i can show more information on each row in a proper format. Any ideas ?
You need TreeTable functionality. I bet this article will help you.
You will need to have the table model add/remove the subcategory rows when the button on the category is clicked.
You should look at NetBeans Outline. Here's an example that shows how it looks.

Categories

Resources