简体   繁体   English

AWT Textfield在MicroSoft JVM上表现异常

[英]AWT Textfield behaves weird with MicroSoft JVM

I am facing a weird problem when using MicroSoft JVM to run my Applet. 使用MicroSoft JVM运行Applet时,我遇到一个奇怪的问题。 I have an AWT panel with 4 textfields which is added to a dialog box. 我有一个带有4个文本字段的AWT面板,该面板已添加到对话框中。 Everything goes fine until I enter a decimal value into the textfield and close the dialog box. 一切正常,直到我在文本字段中输入十进制值并关闭对话框。 When i reopen the dialog box the textfield inside the panel with all the decimal digits (entered in the previous step) behaves weird. 当我重新打开对话框时,面板中带有所有十进制数字的文本字段(在上一步中输入)表现得很奇怪。 The decimal values along with the WHITE area inside the textfield moves to the left and hides the digits. 十进制值以及文本字段内的WHITE区域向左移动并隐藏数字。 When I click inside the textfield it becomes normal. 当我在文本字段内单击时,它变为正常。 The Panel earlier had gridlayout and I even tried changing it to gridbaylayout and still the problem persist. 小组先前有gridlayout,我什至尝试将其更改为gridbaylayout,但问题仍然存在。

NOTE: All Development are pertained to JRE1.1 to compatibility with MS JVM 注意:所有开发都与JRE1.1有关,以与MS JVM兼容

If any can help me with this it would be a great help. 如果有什么可以帮助我的,那将是一个很大的帮助。 Thanks in advance. 提前致谢。

 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);
..............

.........

}

I figured out an solution for this problem. 我想出了解决这个问题的方法。 Placing the textfield cursor position at 0 (zero) once the "OK" is clicked seems to fix this problem. 单击“确定”后,将文本字段光标位置设置为0(零)似乎可以解决此问题。 Here is the code.... 这是代码...

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM