import java.applet.*; import java.awt.*; public class ChoiceCut extends Applet { public void init() { setBackground(Color.yellow); setLayout(new GridBagLayout()); Panel bluePanel = new Panel(); bluePanel.setBackground(Color.blue); bluePanel.setLayout(new GridBagLayout()); constrain(this, bluePanel, 0, 0, 1, 1, GridBagConstraints.NORTH, 0, 0, 0, 0, GridBagConstraints.HORIZONTAL, 1, 0); Choice choice = new Choice(); choice.addItem("Some long but necessarily detailed text for the first item in the Choice"); choice.addItem("Other text for the second item"); constrain(bluePanel, choice, 0, 0, 1, 1, GridBagConstraints.NORTH, 0, 0, 0, 0, GridBagConstraints.HORIZONTAL, 1, 0); Panel redPanel = new Panel(); redPanel.setLayout(new GridBagLayout()); redPanel.setBackground(Color.red); constrain(this, redPanel, 1, 0, 1, 1, GridBagConstraints.NORTH, 0, 0, 0, 0, GridBagConstraints.NONE, 0, 0); Canvas canvas = new MyCanvas(); constrain(redPanel, canvas, 0, 0, 1, 1, GridBagConstraints.NORTH, 0, 0, 0, 0, GridBagConstraints.NONE, 0, 0); } static final void constrain(Container container, Component component, int grid_x, int grid_y, int grid_width, int grid_height, int anchor, int topPad, int leftPad, int bottomPad, int rightPad, int fill, double weightx, double weighty) { GridBagConstraints c = new GridBagConstraints(); c.gridx = grid_x; c.gridy = grid_y; c.gridwidth = grid_width; c.gridheight = grid_height; c.anchor = anchor; c.insets.top = topPad; c.insets.left = leftPad; c.insets.bottom= bottomPad; c.insets.right = rightPad; c.fill = fill; c.weightx = weightx; c.weighty = weighty; ((GridBagLayout)container.getLayout()).setConstraints(component, c); container.add(component); } } // END OF Class ChoiceCut class MyCanvas extends Canvas { public final Dimension getMinimumSize() { return (new Dimension(100, 100)); } public final Dimension getPreferredSize() { return(getMinimumSize()); } } // END OF Class MyCanvas