Thanks!
That solution works great until I put it that splitterView inside a JTabbedPane with the add function.
As you can see, I'm not clear about weather I need JPanels or not for each tabbed pane.
Now the old symptoms are back where the top pain is distorted. And I cannot figure out where to put the "applet.pane.setDividerLocation(.5);//<-----must be after setVisible(true);" to accommodate an applet where there is no main.
I'm trying to follow the example at
http://www.isr.umd.edu/~austin/ence200.d/swing.d/components.d/DemoTabbedPane.java Why would JTabbedPane.add make the upper splitter pane act differently?
Thanks,
Siegfried
// modified from
http://www.isr.umd.edu/~austin/ence200.d/swing.d/components.d/DemoTabbedPane.java /*
*/
import java.awt.*;
import javax.swing.*;
public class DemoTabbedPane extends JApplet {
Container container = null;
private JTabbedPane tabbedPane;
private JPanel[] panel = new JPanel[]{createPage1(), createPage2(), createPage3()};
JApplet [] k = new JApplet[]{new GraphicsOnly(), new MatrixView()};
JPanel [] p = new JPanel[]{new JPanel(), new JPanel()};
{
for(int j= k.length-1; j >= 0; --j ){
k[j].init();
p[j].add(k[j]);
}
}
JApplet [] g = new JApplet[]{new GraphicsOnly(), new MatrixView(), new SplitterView(k[0],k[1])};
public void init() {
//1. Get a handle on the applet's content pane.
container = this.getContentPane();
// NOTE: to reduce the amount of code in this example, it uses
// panels with a NULL layout. This is NOT suitable for
// production code since it may not display correctly for
// a given look-and-feel.
JPanel topPanel = new JPanel();
topPanel.setLayout( new BorderLayout() );
getContentPane().add( topPanel );
// Create the tab pages
//createPage1(); createPage2(); createPage3();
// Create a tabbed pane
tabbedPane = new JTabbedPane();
//SplitterView applet = new SplitterView(k[0], k[1]/*new JPanel(),new JPanel()*/);
for(JApplet j : g) j.init();
tabbedPane.addTab( "Page 1", panel[0] );
tabbedPane.addTab( "Page 2", panel[1] );
tabbedPane.addTab( "Page 3", panel[2] );
tabbedPane.addTab("page 4", g[0]);
tabbedPane.addTab("page 5", g[1]);
tabbedPane.addTab("page 6", g[2]);
topPanel.add( tabbedPane, BorderLayout.CENTER );
}
public JPanel createPage1() {
JPanel panel1 = new JPanel();
panel1.setLayout( null );
JLabel label1 = new JLabel( "Username:" );
label1.setBounds( 10, 15, 150, 20 );
panel1.add( label1 );
JTextField field = new JTextField();
field.setBounds( 10, 35, 150, 20 );
panel1.add( field );
JLabel label2 = new JLabel( "Password:" );
label2.setBounds( 10, 60, 150, 20 );
panel1.add( label2 );
JPasswordField fieldPass = new JPasswordField();
fieldPass.setBounds( 10, 80, 150, 20 );
panel1.add( fieldPass );
return panel1;
}
public JPanel createPage2() {
JPanel panel2 = new JPanel();
panel2.setLayout( new BorderLayout() );
panel2.add( new JButton( "North" ), BorderLayout.NORTH );
panel2.add( new JButton( "South" ), BorderLayout.SOUTH );
panel2.add( new JButton( "East" ), BorderLayout.EAST );
panel2.add( new JButton( "West" ), BorderLayout.WEST );
panel2.add( new JButton( "Center" ), BorderLayout.CENTER );
return panel2;
}
public JPanel createPage3() {
JPanel panel3 = new JPanel();
panel3.setLayout( new GridLayout( 3, 2 ) );
panel3.add( new JLabel( "Field 1:" ) );
panel3.add( new TextArea() );
panel3.add( new JLabel( "Field 2:" ) );
panel3.add( new TextArea() );
panel3.add( new JLabel( "Field 3:" ) );
panel3.add( new TextArea() );
return panel3;
}
public static void main(String[] args) {
JApplet applet = new DemoTabbedPane();
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().add(applet);
f.setSize(400,400);
f.setLocation(200,200);
// Since there is no AppletContext we have to
// call the required methods in the applet.
applet.init();
f.setVisible(true);
}
}