Can anyone help me with this problem????
I have 3 buttons on a panel (on the right side of a jSplitPane.
When resizing the window no scrollbars are added.
But I declared VERTICAL_SCROLLBAR_AS_NEEDED and HORIZONTAL_SCROLLBAR_AS_NEEDED !!!!
What do I have to do to see scrollbars instead???
Here is my simple(?) code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Frame1 extends JFrame {
JPanel contentPane;
BorderLayout borderLayout1 = new BorderLayout();
JSplitPane jSplitPane1 = new JSplitPane();
JTree jTree1 = new JTree();
JScrollPane jScrollPane1 = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
JPanel jPanel1 = new JPanel();
JButton jButton1 = new JButton();
JButton jButton2 = new JButton();
JButton jButton3 = new JButton();
//Construct the frame
public Frame1() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
contentPane = (JPanel) this.getContentPane();
contentPane.setLayout(borderLayout1);
this.setSize(new Dimension(598, 386));
jPanel1.setLayout(null);
jButton1.setBounds(new Rectangle(92, 110, 81, 26));
jButton2.setBounds(new Rectangle(92, 150, 81, 26));
jButton3.setBounds(new Rectangle(92, 190, 81, 26));
contentPane.add(jSplitPane1, BorderLayout.CENTER);
jSplitPane1.add(jTree1, JSplitPane.LEFT);
jSplitPane1.add(jScrollPane1, JSplitPane.RIGHT);
jPanel1.add(jButton1, null);
jPanel1.add(jButton2, null);
jPanel1.add(jButton3, null);
jScrollPane1.getViewport().add(jPanel1, null);
}
//Overridden so we can exit when window is closed
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}
}
Roland - 31 Jan 2005 11:12 GMT
> Can anyone help me with this problem????
> I have 3 buttons on a panel (on the right side of a jSplitPane.
[quoted text clipped - 4 lines]
>
> Here is my simple(?) code:
[snipped]
Because your jPanel1 has no layoutmanager.
I removed jPanel1.setLayout(null) and after resizing the frame small
enough, a horizontal scrollbar appeared.
Choose an appropriate layoutmanager for your panel.

Signature
Regards,
Roland de Ruiter
___ ___
/__/ w_/ /__/
/ \ /_/ / \
Maarten Versteeg - 31 Jan 2005 11:23 GMT
Roland,
I'm a newbe with Java. So I don't understand you.
Can you give me an example?????
Greetz
Roland - 31 Jan 2005 12:53 GMT
> Roland,
>
[quoted text clipped - 3 lines]
>
> Greetz
For the scrollpane to decide when it has to display scrollbars, its
needs to know the size of the component it's decorating. Normally, the
component's layoutmanager is capable of calculating the component's size
(different layoutmanager arrange child components in different ways,
which of course affects the size of the component).
Setting a component's layoutmanager to null disables the ability to
calculate the size of the component properly, and causes, AFAIK in case
of a JPanel, the component's minimum size to be returned. I guess, for a
JPanel the minimum size is 0 by 0 (unless it has been explicitly set),
and therefore the scrollpane will never show its scrollbars.
Further reading, see the Java tutorial:
<http://java.sun.com/docs/books/tutorial/>
<http://java.sun.com/docs/books/tutorial/uiswing/layout/index.html>
<http://java.sun.com/docs/books/tutorial/uiswing/layout/none.html>

Signature
Regards,
Roland de Ruiter
___ ___
/__/ w_/ /__/
/ \ /_/ / \
klynn47@comcast.net - 31 Jan 2005 13:52 GMT
I mostly use setLayout(null) on Components. To make sure the scrollbars
appear, you can call setPreferredSize and revalidate on the Component
in the scroll pane.
Maarten Versteeg - 31 Jan 2005 11:24 GMT
I removed
jPanel1.setLayout(null);
but nothing happened....