(Apple problem # 3565837)
Expected behavior: If a Choice component is too long, the end of the text of the items in the Choice should be cut off. This is the behavior seen in Java 1.3.1 on Macintosh, Sun 1.4.2 on Windows and Microsoft 1.1.4 on Windows.
Observed behavior: Using Java 1.4.x on Macintosh the right end of the Choice is cut off, leaving no Choice control and making it unclear to the user that the component is a Choice and how to use it.
If you have any insights, workarounds or comments about this test page please contact Mickey Segal. A listing of many Java resources is at this link.
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