Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

How to add JTable into a JPanel

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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,
GUI.png
[Thumbnail for GUI.png]
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?)
 
Marshal
Posts: 74766
336
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic