Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a JTable without a JScrollpane

I have done some pretty decent searching and i cant quite fine what im looking for. basically i want a JTable in a JPanel and for that JPanel to re-size itself per the size of the JTable. i know the usual way of implementing a JTable is to use the JScrollpane but in this circumstance it is unnecessary and it makes my program look ... messy.

the reason i cant find the answer i need is everytime someone asks about a JTable in a JPanel someone gives them the answer of putting it in the scrollpane. im aware of the advantages to using the scrollpane but in this circumstance they aren't advantageous.

like image 826
user1027959 Avatar asked Feb 20 '23 05:02

user1027959


1 Answers

  1. yes is possible add JTable to the JPanel, notice with a few row that fills real screen resolution

  2. you have to add TableHeader separatelly to the container too, otherwise isn't added, nor to be visible, for JTable into JScrollPane isn't required add or define TableHeader separatelly

  3. better could be to remove borders from JScrollPane.setBorders(null) and with to disable VERTICAL and HORIZONTAL_SCROLLBAR to NEVER

  4. for shrinking the wider JScrollPane to fits to the JTables Dimension is possible to use table.setPreferredScrollableViewportSize(table.getPreferredSize());

like image 177
mKorbel Avatar answered Mar 06 '23 08:03

mKorbel