AWT Textfield对MicroSoft JVM表现得很奇怪

时间:2010-05-21 23:40:26

标签: java jvm awt

使用MicroSoft JVM运行Applet时,我遇到了一个奇怪的问题。我有一个带有4个文本字段的AWT面板,它被添加到一个对话框中。一切顺利,直到我在文本字段中输入小数值并关闭对话框。当我重新打开对话框时,面板内的文本字段包含所有小数位(在上一步中输入)表现得很奇怪。文本字段内的十进制值和WHITE区域向左移动并隐藏数字。当我在文本字段内单击时,它变得正常。小组早先有网格布局,我甚至尝试将其更改为gridbaylayout,但问题仍然存在。

注意:所有开发都与JRE1.1有关,与MS JVM的兼容性

如果有任何可以帮助我的话,这将是一个很大的帮助。提前致谢。

 public MyPanel(Dialog myDialog)
 {
  Panel panel = new Panel();
  this.dialog = myDialog;

//Previous code with grid layout

/*  panel.setLayout(new GridLayout2(4,2,2,2));
  panel.add(new Label("Symbol:"));
        panel.add(symbolField = new TextField("",20));
  panel.add(new Label("Quantity:"));
  panel.add( qtyField = new TextField());
  panel.add(new Label("Price per Share:"));
  panel.add( costField = new TextField());
  panel.add(new Label("Date Acquired:"));
  panel.add( purchaseDate = new TextField() );*/

  GridBagLayout gridbag = new GridBagLayout();
  System.out.println("######## Created New GridBagLayout");

  GridBagConstraints constraints = new GridBagConstraints();
  panel.setLayout( gridbag );

  constraints = buildConstraints( constraints, 0, 0, 1, 1, 1.5, 1 );
  constraints.anchor = GridBagConstraints.WEST;
  constraints.fill = GridBagConstraints.HORIZONTAL;
  panel.add( new Label("Symbol:"), constraints);

  constraints = buildConstraints( constraints, 1, 0, 1, 1, 1.5, 1 );
  constraints.anchor = GridBagConstraints.WEST;
  constraints.fill = GridBagConstraints.HORIZONTAL;
  panel.add( symbolField = new TextField("",20), constraints);

  constraints = buildConstraints( constraints, 0, 1, 1, 1, 1.5, 1 );
  constraints.anchor = GridBagConstraints.WEST;
  constraints.fill = GridBagConstraints.HORIZONTAL;
  panel.add( new Label("Quantity:"), constraints);

  constraints = buildConstraints( constraints, 1, 1, 1, 1, 1.5, 1 );
  constraints.anchor = GridBagConstraints.WEST;
  constraints.fill = GridBagConstraints.HORIZONTAL;
  panel.add( qtyField = new TextField(), constraints);

  constraints = buildConstraints( constraints, 0, 2, 1, 1, 1.5, 1 );
  constraints.anchor = GridBagConstraints.WEST;
  constraints.fill = GridBagConstraints.HORIZONTAL;
  panel.add( new Label("Price per Share:"), constraints);

  constraints = buildConstraints( constraints, 1, 2, 1, 1, 1.5, 1 );
  constraints.anchor = GridBagConstraints.WEST;
  constraints.fill = GridBagConstraints.HORIZONTAL;
  panel.add( costField = new TextField(), constraints);

  constraints = buildConstraints( constraints, 0, 3, 1, 1, 1.5, 1 );
  constraints.anchor = GridBagConstraints.WEST;
  constraints.fill = GridBagConstraints.HORIZONTAL;
  panel.add( new Label("Date Acquired:"), constraints);

  constraints = buildConstraints( constraints, 1, 3, 1, 1, 1.5, 1 );
  constraints.anchor = GridBagConstraints.WEST;
  constraints.fill = GridBagConstraints.HORIZONTAL;
  panel.add( purchaseDate = new TextField(), constraints);
..............

.........

}

1 个答案:

答案 0 :(得分:0)

我找到了解决这个问题的方法。单击“确定”后,将文本字段光标位置置于0(零)似乎可以解决此问题。这是代码....

symbolField.setCaretPosition(0);  
qtyField.setCaretPosition(0);  
costField.setCaretPosition(0);