• Post Reply Bookmark Topic Watch Topic
  • New Topic

Using scrollable jtable in swing.

 
Ashwani Singh
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to add horizontal scrolling option to the jtable wich i have in my gui.So i dragged a jtable from palette in netbeans,then i dragged a scrollpane in that frame.Now how to add jtable to the scrollpane?I tried to go to the customize code option of the scrollpane and pass the jtable in the scrollpane constructor as:

jScrollPane6 = new javax.swing.JScrollPane(Main_frame.jTable4);
but its not working.Both,jtable and jscrollpane are displayed seperately when i run the application.
Please guide.
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ItDoesntWorkIsUseless TellTheDetails
Please post your SSCCE code so we can take a look

Usually you would go about this way


 
Ashwani Singh
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
since i have not coded to add jtable and jscrollpane,i just dragged and dropped,i do not have any code to post here.
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ashwani Singh wrote:since i have not coded to add jtable and jscrollpane,i just dragged and dropped,i do not have any code to post here.

Then where did you get this from?

Surely the IDE generated the code for you?
 
Ashwani Singh
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I right clicked on the jscrollpane component which i have dragged from pallete to frame,selected customize code option and in that there was a custom create option where i can modify the default code generated by the netbeans,there i modified the code which i posted here.
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Without looking at the code, we cannot help you. Maybe it's time you considered dropping the DnD and started coding by hand.
 
Ashwani Singh
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its just the gui creation in which i have taken the help of the IDE.I have done rest of the event handling codes.
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ashwani Singh wrote:Its just the gui creation in which i have taken the help of the IDE.I have done rest of the event handling codes.

And you have a GUI problem
 
Ashwani Singh
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes because that's something which i have not done.Some event handling issues are manageble since i know about the code.
 
Darryl Burke
Bartender
Posts: 5154
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Without a SSCCE, I can only hazard a guess that you may need to set the suto resize mode of the table. But there's a very good tutorial linked from the JTable API, and you can probably find what you want there.

edit: After understanding that a Component can have only one parent.
 
Nam Ha Minh
Ranch Hand
Posts: 509
Eclipse IDE Firefox Browser Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ashwani Singh,

Normally when you drop a JTable from the palette, NetBeans automatically wraps it in a JScrollpane for you. So you don't need to drop a JScrollpane!
 
Ashwani Singh
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nam Ha Minh wrote:Hi Ashwani Singh,

Normally when you drop a JTable from the palette, NetBeans automatically wraps it in a JScrollpane for you. So you don't need to drop a JScrollpane!



That i can notice but i can not see the scrollbars while running the application.I have set the autoResizeMode to OFF as well.
 
Ashwani Singh
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please find below the snapshot of the customized code generated by netbeans.
jtable_issue.png
[Thumbnail for jtable_issue.png]
 
Ashwani Singh
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Most importantly i want column names to be visible ,no matter i can see only few columns at a time and then have to scroll to view other columns.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!