0

I have added the components to a JPanel and that JPanel to a JScrollPane. But I need to give specific bounds to the components that I have added(without using a layout manager).When use a null layout to set the bounds that scroll bar is not visible.

mKorbel
  • 109,525
  • 20
  • 134
  • 319
user2723764
  • 25
  • 1
  • 2
  • 6
  • Why exactly no layout manager? – arynaq Aug 28 '13 at 08:32
  • I found it a little complicated when a layout manager is used.For some rows there are two components ,sometimes four components.Is there a way to use a layout manager to this? – user2723764 Aug 28 '13 at 08:57
  • I'm using `GridBagLayout`, although some might hate it. There are other layout managers which might be better, such as [JGoodies `FormLayout`](http://www.jgoodies.com/freeware/libraries/forms/). More information [here](http://docs.oracle.com/javase/tutorial/uiswing/layout/visual.html). – Moritz Petersen Aug 28 '13 at 08:59
  • 1
    Java GUIs might have to work on a number of platforms, on different screen resolutions & using different PLAFs. As such they are not conducive to exact placement of components. To organize the components for a robust GUI, instead use layout managers, or [combinations of them](http://stackoverflow.com/a/5630271/418556), along with layout padding & borders for [white space](http://stackoverflow.com/q/17874717/418556). – Andrew Thompson Aug 28 '13 at 09:03
  • 1
    just for emphasis: in Swing, there is exactly **no** way around using LayoutManagers - the sooner you start learning to use them the sooner you'll harvest its goodies :-) – kleopatra Aug 28 '13 at 09:25
  • Thanks a lot Moritz Petersen.I tried GridBagLayout and it seems good.But I'm still unable to arrange the components in the way I want. – user2723764 Aug 28 '13 at 09:37
  • `But I'm still unable to arrange the components in the way I want` - well if you want more help then you will need to provide more details. We are not mind readers. We can't guess what you are thinking. – camickr Aug 28 '13 at 15:15

1 Answers1

0

It's best to use a layout manager. They might be a little "scary" (especially GridBagLayout) but once you get your head around them, they're really easy to use and implement.

Ben Dale
  • 2,492
  • 1
  • 14
  • 14