Hi Steven,
A Frame's default layout is Border Layout, so if u dont specify any layout, it just adds components in the CENTER ( like whats happening in your case ), so what u can do is specify BorderLayout & add the 2 panels in CENTER & EAST/WEST , or use FlowLayout & maximize the Panels.
Also I changed maximum size to preferred size.
this is ur modified code:
import java.awt.*;
import javax.swing.*;
class TSPanel extends JPanel
{
public TSPanel ()
{
this.setBackground (Color.blue);
Dimension d1 = new Dimension(250, 150);
//this.setMaximumSize(d1);
this.setPreferredSize(d1);
}
public void paintComponent (Graphics g)
{
super.paintComponent(g);
g.drawString ("Hello World!", 100, 100);
}
}
public class ts4copy
{
public static void main (
String[] argv)
{
JFrame frame = new JFrame ();
frame.setTitle ("Hello World Test");
frame.setResizable (true);
frame.setSize (500, 300);
TSPanel panel = new TSPanel ();
TSPanel panel1 = new TSPanel ();
frame.getContentPane().setLayout(new BorderLayout());
frame.getContentPane().add (panel,BorderLayout.CENTER);
frame.getContentPane().add (panel1,BorderLayout.WEST);
frame.setVisible (true);
}
}
Should do it!
Vinod