I am having problems in getting the scrollpane in a tabbed pane with each tab being a JPanel with Null layout .
In detail , I am having a JTabbedPane where each Tab is a JPanel with layout set to null using panel.setLayout(null) and all the components are added using the Bounds ...and i am wrapping the each panel in a JscrollPane . But the scroll pane is not coming . But the same works fine when i add the components to the panel using a borderlayout instead of null layout
JPanel panel = new JPanel(); // panel.setLayout(new GridBagLayout());(Works fine if i use this) panel.setLayout(null); panel.setBounds(0,0,965,150); JLabel label = new JLabel("asjfdashjsfjfgasfsasjfdashjsfjfgasfsasjfdashjsfjfgasfsasjfdashjsfjfgasfsasjfdashjsfjfgasfsasjfdashjsfjfgasfsasjfdashjsfjfgasfs"); label.setBounds(10,10,831,81); panel.add(label); JTextField field = new JTextField(10); field.setBounds(861,10,94,18); panel.add(field);
I never setLayout(null), but try this instead of panel.setBounds:
There is no emoticon for what I am feeling!
Joined: Sep 21, 2003
thanks a lot , it worked but if you don't mind can you let me know how this one line made a such huge difference ??
Joined: Sep 16, 2005
If you add components to a container that has a layout manager, the job of that layout manager is to set the size and location (the bounds) of those components. If you set them yourself by calling the components' setSize/setLocation/setBounds method, those calls may have no effect because the layout manager will be calling those methods again, later in the layout process. On the other hand, if you want to *influence* the way the layout manager sets those components' sizes you call either call their setPreferredSize / setMinimumSize / setMaximumSize methods or subclass and override getPreferredSize / getMinimumSize / getMaximumSize methods. This is because the layout manager *may* query those properties in the layout process.
In your case, "panel" was placed inside JScrollPane, which you can think of a specialized container with a distinguished child component, the one placed in the center (the "viewport"). When a JScrollPane is asked for its preferred size, it will in turn ask its viewport component what its preferred size is. That's why it is important for that component to have a sensible preferred size. Usually this comes for free for container components with layout managers, but you fired yours... [ December 20, 2005: Message edited by: Jeff Albrechtsen ]
Joined: Sep 21, 2003
Thanks a lot jeff
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
subject: JscrollPane with JTabbedPane for NullLayout