resizing problems.

Hi.

The code below is meant to show two visad displays in one container. I am
interested in having one display take up 60% of the container's width, and
the other 40%. I am using GridBagLayout to achieve this specification with
the "weightx" option to specify the 60% and 40% values. If you run this
code, however, you will note that it does not consistently preserve these
proportion before and after resizing. You can test this with a ruler. Try
resizing the window and you will see what I mean. 

(Note: the visad displays are contained within JPanels. The JPanels
are then added to the container.) 

If panel1 and panel2 are empty, however, the correct proportions seem to
be maintained before and after resizing. You can comment out

panel1.add((new DisplayImplJ2D("2")).getComponent());
panel2.add((new DisplayImplJ3D("3")).getComponent());

to test this.

Does anyone know what is going on, and how to fix this problem? Is this a
visad specific problem?

Thanks for your time.

-Julien

*****************************************************************

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.Border;

import visad.*;
import visad.java3d.*;
import visad.java2d.*;

public class resize extends JFrame {

    public resize() throws Exception {
        Container contentPane = getContentPane();
        GridBagLayout gridbag = new GridBagLayout();
        GridBagConstraints c = new GridBagConstraints();
        contentPane.setLayout(gridbag);
        c.fill = GridBagConstraints.BOTH;

        Border raisedBevel = BorderFactory.createRaisedBevelBorder();

        JPanel panel1 = new JPanel();
        panel1.add((new DisplayImplJ2D("2")).getComponent());
        panel1.setBorder(raisedBevel);
        c.weightx = 0.6;
        c.weighty = 1.0;
        c.gridx = 0;
        c.gridy = 0;
        gridbag.setConstraints(panel1, c);
        contentPane.add(panel1);

        JPanel panel2 = new JPanel();
        panel2.add((new DisplayImplJ3D("3")).getComponent());
        panel2.setBorder(raisedBevel);
        c.weightx = 0.4;
        c.weighty = 1.0;
        c.gridx = 1;
        c.gridy = 0;
        gridbag.setConstraints(panel2, c);
        contentPane.add(panel2);

    public static void main(String args[]) throws Exception {
        resize window = new resize();

        window.setTitle("GridBagLayout");
        window.pack();
        window.setVisible(true);
    }
}


  • 2000 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the visad archives: