[Logo] JavaRanch » JavaRanch Saloon
  Search | FAQ | Recent Topics | Hot Topics
Register / Login


Win a copy of Flex 4 in Action this week in the Flex forum!
Reply Bookmark it! Watch this topic JavaRanch » Forums » Java » Swing / AWT / SWT / JFace
 
RSS feed
 
New topic
Author

Scrollbar for jtable

janavi patel
Greenhorn

Joined: Jul 01, 2009
Messages: 13

hello friends..

Please tell me how to add vertical and horizantal scrollbar in jtable?
Maneesh Godbole
Bartender

Joined: Jul 26, 2007
Messages: 4234


Swing related. Moving.

work is the scourge of the drinking class
janavi patel
Greenhorn

Joined: Jul 01, 2009
Messages: 13

Thanks for reply...

but I already tried everything......and nothing is helpful for me........
Maneesh Godbole
Bartender

Joined: Jul 26, 2007
Messages: 4234

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.

work is the scourge of the drinking class
Rob Prime
Bartender

Joined: Oct 27, 2005
Messages: 8776

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?

SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
Michael Dunn
Rancher

Joined: Jun 09, 2003
Messages: 3090

> 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.
Rohit Aggarawal
Greenhorn

Joined: Jun 26, 2009
Messages: 29

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)

SCJP 6.0
SCBCD for JEE 5

Rohit Aggarawal
Greenhorn

Joined: Jun 26, 2009
Messages: 29

Or send me your code...

SCJP 6.0
SCBCD for JEE 5

Maneesh Godbole
Bartender

Joined: Jul 26, 2007
Messages: 4234

Rohit,
Please read this: http://faq.javaranch.com/java/UseTheForumNotEmail

work is the scourge of the drinking class
janavi patel
Greenhorn

Joined: Jul 01, 2009
Messages: 13

here is my code

Rohit Aggarawal
Greenhorn

Joined: Jun 26, 2009
Messages: 29

Ok. I got it...

SCJP 6.0
SCBCD for JEE 5

Maneesh Godbole
Bartender

Joined: Jul 26, 2007
Messages: 4234



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

This message was edited 1 time. Last update was at by Maneesh Godbole


work is the scourge of the drinking class
janavi patel
Greenhorn

Joined: Jul 01, 2009
Messages: 13

I tried this code but this is also not working.....
janavi patel
Greenhorn

Joined: Jul 01, 2009
Messages: 13

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....
Dany Rouss
Greenhorn

Joined: Jul 02, 2009
Messages: 2

[MG]Edited to remove hijack.

Danny,
Welcome to the Ranch.
Please start a new thread for your question.

This message was edited 1 time. Last update was at by Maneesh Godbole

Maneesh Godbole
Bartender

Joined: Jul 26, 2007
Messages: 4234

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
Vandre Caetano
Greenhorn

Joined: Dec 19, 2007
Messages: 8

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

This message was edited 2 times. Last update was at by Vandre Caetano

janavi patel
Greenhorn

Joined: Jul 01, 2009
Messages: 13

Here is my another code....

Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Messages: 677

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:

This message was edited 1 time. Last update was at by Rob Camick

janavi patel
Greenhorn

Joined: Jul 01, 2009
Messages: 13

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]

This message was edited 2 times. Last update was at by Maneesh Godbole

Rohit Aggarawal
Greenhorn

Joined: Jun 26, 2009
Messages: 29

Code is slightly modified for the method MyFrame8 and that works now. Please use this piece of code...

This message was edited 3 times. Last update was at by Rohit agl


SCJP 6.0
SCBCD for JEE 5

Maneesh Godbole
Bartender

Joined: Jul 26, 2007
Messages: 4234

Rohit,
Please use code tags
You can add them to your existing post by clicking on the button

work is the scourge of the drinking class
Rohit Aggarawal
Greenhorn

Joined: Jun 26, 2009
Messages: 29

Maneesh,

Done as per your suggestion.

-Rohit

This message was edited 1 time. Last update was at by Rohit agl


SCJP 6.0
SCBCD for JEE 5

Maneesh Godbole
Bartender

Joined: Jul 26, 2007
Messages: 4234

Thank you

work is the scourge of the drinking class
janavi patel
Greenhorn

Joined: Jul 01, 2009
Messages: 13

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

Joined: Jul 26, 2007
Messages: 4234

Did you try out Rob Camick's code?

work is the scourge of the drinking class
janavi patel
Greenhorn

Joined: Jul 01, 2009
Messages: 13

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
Rancher

Joined: Jun 09, 2003
Messages: 3090

> 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
Greenhorn

Joined: Jun 26, 2009
Messages: 29

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

SCJP 6.0
SCBCD for JEE 5

Maneesh Godbole
Bartender

Joined: Jul 26, 2007
Messages: 4234

"Rohit agl",
Please check your private messages for an important administrative matter.

work is the scourge of the drinking class
janavi patel
Greenhorn

Joined: Jul 01, 2009
Messages: 13

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

Joined: Jul 26, 2007
Messages: 4234

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

Joined: Jul 01, 2009
Messages: 13

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

Joined: Jul 26, 2007
Messages: 4234

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

Joined: Jul 01, 2009
Messages: 13

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
Ranch Hand

Joined: Jun 13, 2009
Messages: 677

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
Rancher

Joined: Jun 09, 2003
Messages: 3090

> 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.

Dipanjan Kailthya
Greenhorn

Joined: Jul 04, 2009
Messages: 20

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)

This message was edited 4 times. Last update was at by Dipanjan Kailthya

 
 
 
Reply Bookmark it! Watch this topic JavaRanch » Forums » Java » Swing / AWT / SWT / JFace
 
RSS feed
 
New topic
JProfiler
Get rid of your performance problems and memory leaks!