开发者

AWT Textfield behaves weird with MicroSoft JVM

开发者 https://www.devze.com 2022-12-31 11:55 出处:网络
I am facing a weird problem when using MicroSoft JVM to run my Applet. I have an AWT panel with 4 textfields which is added to a dialog box. Everything goes fine until I enter a decimal value into the

I am facing a weird problem when using MicroSoft JVM to run my Applet. I have an AWT panel with 4 textfields which is added to a dialog box. 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. 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.

NOTE: All Development are pertained to JRE1.1 to compatibility with 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("S开发者_JS百科ymbol:"), 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. Here is the code....

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

精彩评论

暂无评论...
验证码 换一张
取 消