Java GUI panel size and resizing issues...
From: TR (t_at_r.t)
Date: 10/09/04
- Next message: Raymond DeCampo: "Re: Java GUI panel size and resizing issues..."
- Previous message: code astronomer: "Reading a webpage"
- Next in thread: Raymond DeCampo: "Re: Java GUI panel size and resizing issues..."
- Reply: Raymond DeCampo: "Re: Java GUI panel size and resizing issues..."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 9 Oct 2004 11:42:08 -0400
Hi All:
I have a simple test GUI that has 2 panels (a left side and a right side),
and each panel is displaying an image. The left panel has a hardcoded size
of (600,400) using the Dimension() function. Likewise, the right panel has a
hardcoded size of 300, 200.
Problem 1: I would think that when the GUI is launched, the image in the
right panel would be twice as small as the image on the left. However, they
are the same size. Does anyone know why this might be? Further, is there a
way to set panel and image widths to be a percentage of the width of the
parent panel? For example, the left side set to 67% of the total parent
panel width, and the right side sett to 33% of the parent panel width.
Problem 2: When the window is resized in the horizontal direction, the
panels and images also resize. However, when the window is resized in the
veritcal direction, the panels and images do not resize, and eventually
become covered up as the window becomes very small. Is there any way to get
the panels and images to resize in both directions as the window is resized?
Thanks in advance for any help. Code follows:
-------------------------------
import java.awt.*;
import javax.swing.*;
public class JPanels extends JFrame {
public static void main(String[] args) {
new JPanels();
}
public JPanels() {
super("Test Window");
Container content = getContentPane();
content.setBackground(Color.lightGray);
JPanel bothsides = new JPanel(new GridLayout(1, 2));
JPanel leftside = new JPanel();
leftside.setPreferredSize(new Dimension(600, 400));
ImageIcon icon1 = new ImageIcon ("sun.jpg");
leftside.add(new JLabel(icon1));
JPanel rightside = new JPanel();
rightside.setPreferredSize(new Dimension(300, 200));
ImageIcon icon2 = new ImageIcon ("venus.jpg");
rightside.add(new JLabel(icon2));
bothsides.add(leftside);
bothsides.add(rightside);
content.add(bothsides);
pack();
setVisible(true);
}
}
- Next message: Raymond DeCampo: "Re: Java GUI panel size and resizing issues..."
- Previous message: code astronomer: "Reading a webpage"
- Next in thread: Raymond DeCampo: "Re: Java GUI panel size and resizing issues..."
- Reply: Raymond DeCampo: "Re: Java GUI panel size and resizing issues..."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|