import java.awt.*;
import javax.swing.*;
public class SplitPaneDemo extends JFrame {
public SplitPaneDemo() {
super("Split Pane Demo");
Container container = getContentPane();
JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
splitPane.setLeftComponent(new JTree());
JTextArea textArea = new JTextArea();
splitPane.setRightComponent(textArea);
textArea.setLineWrap(true);
container.add(splitPane, BorderLayout.CENTER);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(500, 500);
setVisible(true);
}
public static void main(String[] args) {
new SplitPaneDemo();
}
}
If I dont setLineWrap(true) then I can move the JSplitPane's
separator bar correctly. As it is here, I can move it left,
but not right. It seems like the JTextArea is resizable
bigger, but not smaller, when LineWrap is true.
My actual program is a lot more involved (the right hand side
is a JTextArea in a JPanel (along with other components) on
a JTabbedField on the right hand side of the JSplitPane), but
I'm obviously missing something basic. What's the CORRECT
way to get the above working correctly?
Thanks.
(snipped)
As a supplement to my last post, I can ALMOST get it to work the
way I want like this:
package larry.sybasetexteditor;
import java.awt.*;
import javax.swing.*;
import javax.swing.tree.*;
public class SplitPaneDemo extends JFrame {
public SplitPaneDemo() {
super("Split Pane Demo");
Container container = getContentPane();
JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
DefaultMutableTreeNode root = new DefaultMutableTreeNode("root");
for (int i = 1; i <= 50; i++)
root.add(new DefaultMutableTreeNode("Node " + i));
JTree tree = new JTree(root);
tree.setPreferredSize(new Dimension(200, 500));
splitPane.setLeftComponent(new JScrollPane(tree));
JTextArea textArea = new JTextArea();
textArea.setLineWrap(true);
splitPane.setRightComponent(new JScrollPane(textArea));
container.add(splitPane, BorderLayout.CENTER);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(500, 500);
setVisible(true);
}
public static void main(String[] args) {
new SplitPaneDemo();
}
}
The only problem with this is that it no longer vertically
scrolls through the JTree correctly (note that there are 50
nodes in the tree, but you can't scroll down to see them
all). Any suggestions?
Thanks.
> Larry Coon wrote:
>
> (snipped)
>
> As a supplement to my last post, I can ALMOST get it to work the
> way I want like this:
:
> tree.setPreferredSize(new Dimension(200, 500));
Try setting the minimum size rather than the preferred size. If you want
the JSplitPane to respect that minimum size, set the minimum size of the
component that you place in the JSplitPane, i.e. the JScrollPane(). Note
that you will probably want to choose a smaller height value.
--
Regards,
John McGrath
> Try setting the minimum size rather than the preferred size. If you want
> the JSplitPane to respect that minimum size, set the minimum size of the
> component that you place in the JSplitPane, i.e. the JScrollPane(). Note
> that you will probably want to choose a smaller height value.
Thanks for the reply, John. After a lot more mucking around with it,
it turned out that setting the preferred size of the JScrollPane did
the trick.