Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Swing / AWT / SWT and the fly likes How to add  JTable into a JPanel Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to add  JTable into a JPanel" Watch "How to add  JTable into a JPanel" New topic
Author

How to add JTable into a JPanel

Edwin Montes
Greenhorn

Joined: Feb 25, 2013
Posts: 1
Hi:

First of all I want to apologize if my post doesn't meet the forum standard (it is my first time)

I am working on a personal initiative to create a simple record keeper for my animals. I am almost done with the GUI but having issues adding a jTable into the last jPanel
GUI was done using NetBeans. Here is the code



In the attachment is an image of the actual GUI. Any help will be greatly appreciated.

PD SOrry the labels in the gui are in spanish but I dont think this will prevent anyone from helping.

Best Regards,


[Thumbnail for GUI.png]

Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
generally a JTable is added to a JScrollPane (so headers are shown).

you add the table via the scrollPane's constructor:
= new JScrollPane(table);//other constructors available

or by
scrollPane.setViewportView(table);

but *never* by
scrollpane.add(table);

then you add the scrollPane to the panel.

I don't use netbeans so can't advise on what to to there, or how to modify
the builder-generated GroupLayout code. if no-one comes along that uses
netbeans it might be worth a post in the netbeans forum (netbeans.org?)
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38107
    
  22
Welcome to the Ranch
You didn’t format the code tags correctly, missing out the / from the second tag. but I have corrected that and you can see how much better the post looks
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: How to add JTable into a JPanel
 
Similar Threads
Please help me solve my problem
Problem With GUI of Net Beans
Networked Programs that work across countries
Pressing a button to open a new window
how to set action event