Meaningless Drivel is fun!*
The moose likes Swing / AWT / SWT and the fly likes Center a JPanel in JScrollPane and add a JToolBar Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Center a JPanel in JScrollPane and add a JToolBar" Watch "Center a JPanel in JScrollPane and add a JToolBar" New topic
Author

Center a JPanel in JScrollPane and add a JToolBar

Kay Tracid
Ranch Hand

Joined: Mar 06, 2002
Posts: 148
I add some elements to to my scrollPane unsing a gridlayout. There where in the middle of my ScrollPane. Now I must use a panel with these elements, but the panel is always on top.
1. How can I center a JPanel in a JScrollPane?
2. I want to add a ToolBar to the top and center the panel in my program. How can I do this?
Please help...Thanks a lot!
Here is the code:

[ June 28, 2002: Message edited by: Kay Tracid ]
[ July 01, 2002: Message edited by: Kay Tracid ]
Kay Tracid
Ranch Hand

Joined: Mar 06, 2002
Posts: 148
Please help, it is important for me. I think it is just a layout problem. The toolBar can i add to north in a borderlayout. But how can I center the JPanel in the scrollPane?
Please..........
keerthi matta
Greenhorn

Joined: May 31, 2002
Posts: 27
hi Kay,
Dont worry,
U just need to make 1 change in your code.
1. In PicPanel class , u forgot to set the Layout of the JPanel,
just set the layout to BorderLayout.
and in Main Panel, no need to add the Panels to a JScollPane , u can add directly add the Panels to the SplitPane , adding ScollPane to Panels i think does not effect
hope this would solve ur problem
if i have understood it in right manner
ok njoy coding
keerthi
Kay Tracid
Ranch Hand

Joined: Mar 06, 2002
Posts: 148
Thanks a lot, it works now I thought borderlayout is the default layout. I dont know why I must set it...
 
GeeCON Prague 2014
 
subject: Center a JPanel in JScrollPane and add a JToolBar