Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / November 2004

Tip: Looking for answers? Try searching our database.

JSplitPane resize woes

Thread view: 
Larry Coon - 25 Nov 2004 00:11 GMT
I've reduced my problem to a short, self-contained example,
below.  I have a JFrame that has a JSplitPane, that has a
JTree (left) and JTextArea (right).  I can't get resize
behavior to work correctly.  I've tried many combinations of
setting minimum size & preferred size on each/all of the
components, but nothing did what I wanted.  Here's a minimal
example:

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.
Larry Coon - 25 Nov 2004 02:23 GMT
(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.
John McGrath - 27 Nov 2004 06:50 GMT
> (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.

Signature

Regards,

John McGrath

Larry Coon - 29 Nov 2004 20:35 GMT
> 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.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.