I have a horizontal JSplitPane, the left side of which is occupied by a JTextArea and the right side by a JPanel, which will later contain a JList.
my problem is:
when resize I resize the window:
1. on expanding: the right side of the JSplitPane increases in size ( hence the JPanel increases in size ), while the JTextarea remains the same.
2. on contracting: the JTextArea keeps becoming smaller and until it nearly vanishes, and then the JPanel starts contracting.
It does not matter what corner or what size of the JFrame I use to resize it: the result is the same.
what do i do to reverse the effect but with the following difference:
On resizing, the following happens:
1. on expanding: the size of the JPanel remains the same, and the JTextArea keeps getting bigger
2. on contracting: the size of the JTextArea remains the same, and the JPanel contracts UNTIL IT REACHES A MINIMUM WIDTH. After this width, the JTextArea starts contracting, UNTIL THIS TOO REACHES A MINIMUM SIZE (both height and width). After this limit, no more contraction is possible.
My code is:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.*;
class MultiEditClient extends JFrame
{
public MultiEditClient( String title )
{
super(title);
addComponents();
addMenu();
}
protected void addComponents()
{
this.setBounds( 100,100, 500,500 );
JPanel panel = new JPanel();
JLabel label = new JLabel( "The to-be status bar." );
label.setFont( new Font( Font.SANS_SERIF , Font.PLAIN , 14 ) );
label.setMinimumSize( label.getMaximumSize() );
JTextArea textarea = new JTextArea();
textarea.setPreferredSize( new Dimension(400,400) );
textarea.setMinimumSize( textarea.getMaximumSize() );
JScrollPane scrollForTextArea = new JScrollPane(textarea);
JPanel anotherpanel = new JPanel();
anotherpanel.add( new JButton("Sample Button") );
JSplitPane splitPane = new JSplitPane( JSplitPane.HORIZONTAL_SPLIT, scrollForTextArea, anotherpanel );
splitPane.setOneTouchExpandable(true);
panel.setLayout( new BoxLayout(panel, BoxLayout.PAGE_AXIS ) );
Box vBox = Box.createVerticalBox();
Box hBox2 = Box.createHorizontalBox();
hBox2.add( splitPane );
vBox.add( hBox2 );
vBox.add( Box.createVerticalStrut(5) );
Box hBox = Box.createHorizontalBox();
hBox.add( Box.createHorizontalStrut(5) );
hBox.add( label );
hBox.add( Box.createHorizontalGlue() );
vBox.add( hBox );
vBox.add( Box.createVerticalStrut(2) );
panel.add( vBox );
add( panel );
}
protected void addMenu()
{
JMenuBar menubar = new JMenuBar();
JMenu session = new JMenu( "Session" );
JMenuItem joinSession = new JMenuItem( "Join Session" );
session.add( joinSession );
menubar.add( session );
this.setJMenuBar( menubar );
}
public static void main( String args[] )
{
MultiEditClient theFrame = new MultiEditClient( "MultiEdit Client" );
theFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
theFrame.pack();
theFrame.setVisible( true );
}
}