• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Scrollbar for jtable

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello friends..

Please tell me how to add vertical and horizantal scrollbar in jtable?
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Swing related. Moving.
 
janavi patel
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for reply...

but I already tried everything......and nothing is helpful for me........
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does the panel to which you are adding the table, has a BorderLayout?
It will help us help you better if you tell the details
Also check out this link on how to get the most out of the Ranch.
 
Sheriff
Posts: 22784
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Then you're definitely doing something wrong, because the code Maneesh provided should do just what you need.

Can you show the bit of your code where you add your table to its parent?
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
> but I already tried everything......and nothing is helpful for me........

then you're possibly using a null layout, and not giving anything a size.

we can continue to play 20 guesses, or, if you really want a solution, post your code.
 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use this. It will work ..

JScrollPane scrollPane = new JScrollPane(instance_of_Table);
scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_ALWAYS);
add(scrollPane, BorderLayout.CENTER); (Add should be called for any container....FRame or JPAnel)
 
Rohit Aggarawal
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Or send me your code...
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rohit,
Please read this: http://faq.javaranch.com/java/UseTheForumNotEmail
 
janavi patel
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
here is my code

 
Rohit Aggarawal
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok. I got it...
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Please see my comments.
Recommendations:
1) You do not need p. Discard it.
2) Use p1.add(scrollPane)
3) Use c.add(p1)
4) Even, c.add(scrollPane) will do, if your UI shows only the table.

Recommended reading
http://java.sun.com/docs/books/tutorial/uiswing/components/frame.html
http://java.sun.com/docs/books/tutorial/uiswing/layout/using.html
 
janavi patel
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried this code but this is also not working.....
 
janavi patel
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Manish

but i tried that one also. when i use BorderLayout() it shows empty frame and nothing in it...

i really fade up of this problem....
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[MG]Edited to remove hijack.

Danny,
Welcome to the Ranch.
Please start a new thread for your question.
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

janavi patel wrote:
but i tried that one also. when i use BorderLayout() it shows empty frame and nothing in it...



Like you have been told before, unless you show us your code, we cannot really help you..and even people will get fed up and stop helping you.
So, show us your code
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I changed a few things in the code, here is one that works:



I thing you mixed up a few things like:
# p1.add(header);
# p1.add(table);
# p1.add(pane);
you use this only when there is no scrollpane in the table: http://java.sun.com/docs/books/tutorial/uiswing/components/table.html

I hope it helps
 
janavi patel
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is my another code....

 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why are you trying to write an entire program when you are trying to learn a new concept?. Your question is about a JTable and a scrollbar. People have told you to use a JScrollPane. So only include those two classes in your test programa and keep it simple. Something like this:

 
janavi patel
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are yaar*.... all things are related and impacting each other...thats why....

*Are yaar=="Hey dude" or "Man"

[MG]
Janavi,
We got people from all over the world here.
Please use real words
[/MG]
 
Rohit Aggarawal
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Code is slightly modified for the method MyFrame8 and that works now. Please use this piece of code...
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rohit,
Please use code tags
You can add them to your existing post by clicking on the button
 
Rohit Aggarawal
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maneesh,

Done as per your suggestion.

-Rohit
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you
 
janavi patel
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Rohit..
I tried this code:



but still its not showing a table and positions of all other components is different because of p = new JPanel(); ....

and if I used p = new JPanel(null); then components positions are right as they defined but still not showing a table.......
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you try out Rob Camick's code?
 
janavi patel
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, I tried that.....
It works when there is only container and not panel and it hides all other components....
And when panel is used all positions are proper bue there is no scrollbar....
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
> Yes, I tried that.....

and, as usual, it worked.


> It works when there is only container and not panel and it hides all other components....
> And when panel is used all positions are proper bue there is no scrollbar....

then, why don't you post your (altered Rob Camick's) code to prove the above?
 
Rohit Aggarawal
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear janavi patel

You can use the modified code that was posted by me earlier and It will run like anything. I took not more than 1 minute to modiffy and run your code.
I am still wondeing why that does not work on your machine.

-Rohit
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Rohit agl",
Please check your private messages for an important administrative matter.
 
janavi patel
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Rohit
I tried your code snippet in my program as follows:


1. Now it adds scrollpane to the table but not showing other components.
2. Also shows srollable table for full frame. For this I tried pane.setBounds() but no effect.
3. Doesn't matters panel's layout even whether panel is used or not.


 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

janavi patel wrote:
1. Now it adds scrollpane to the table but not showing other components.
2. Also shows srollable table for full frame. For this I tried pane.setBounds() but no effect.
3. Doesn't matters panel's layout even whether panel is used or not.



I am not surprised. You have chosen to ignore the hints/ready made code provided to you.
Recommended reading
http://java.sun.com/docs/books/tutorial/uiswing/layout/visual.html
 
janavi patel
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
manish
this is last time I am telling to you I tried all hints and every other thing that I can do...
if you cant help or dont want to help then its more better for both of us that you just stay away from this matter.......
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

janavi patel wrote:manish
this is last time I am telling to you I tried all hints and every other thing that I can do...
if you cant help or dont want to help then its more better for both of us that you just stay away from this matter.......



To start with I am a volunteer here and I do not get paid for this work. Even if I was getting paid, I still do not have any reason to put up with this kind of language.
I do not see you trying out my suggestions which I gave here I wonder if you found time to go through the links I had provided.
Michael Dunn (another volunteer) had requested you to

then, why don't you post your (altered Rob Camick's) code to prove the above?

. You did not respond to it. BTW, Rob Camick is another volunteer.

If you want to learn, it might be a good idea to try out suggestions. You can always ask why. If you want ready made solutions (and the learning is not really important), then you are in the wrong place. All volunteers here are entitled to some respect.

Have a nice day and best of luck with your code.
 
janavi patel
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry for that.....
actually I never behave like this with anyone but everytime manish replied against me.....
everytime i said i tried and you just opposed me and nothing else thats why...........
and in my code i did too many changes so its not possible for me to send the code......
and I want to learn thats why I am doing all these things.......

sorry once again......
and I m saying sorry not because you are a volunteer but because of this is not in my nature.......
 
Rob Camick
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I did too many changes so its not possible for me to send the code......



You learn by walking, not running. Forget about your real program, you are just trying to learn basic concepts, so you start with a basic program.

Why do you think I gave you the 10 line complete example program?

That program shows how to display a table with scrollbars. The next step is to add a couple of text fiields. If it works great, if not, then you have a 10-15 line program to post in the forum that we can look at. Once that works you move on to the next step.

Finally, when you understand how LayoutMangers work and how to you add components to a panel you go back to your real program to figure out what you did wrong. We are not here to debug you program for you. Frankly, if you can't figure out how to add components to a panel then you shouldn't be doing Swing programming. This should be the first think you learn because it only gets more difficult.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
> actually I never behave like this with anyone but everytime manish replied against me.....

you've missed the point, totally. There's nothing 'personal' in it.

all everyone is doing is trying to get you to think about what you're doing, how you're going about it,
giving you some hints/nudges in the right direction.
This makes it much easier for you the next time you have a problem.

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Another problem is that you're creating and displaying your GUI objects in the main thread. All that should really be done in the event dispatching thread. If you're using java6, try http://java.sun.com/javase/6/docs/api/javax/swing/SwingUtilities.html#invokeLater(java.lang.Runnable)
 
Bring me the box labeled "thinking cap" ... and then read this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic