JFrameフォームでテキストフィールドを2回設定しましたが、最後に設定したテキストフィールドは残っています。 JFrameフォームを除いて、私はより多くの時間を成功させることができます。たとえば、JFrameフォームで何度もコンポーネントを設定する方法
class test extends JFrame {
public static void main(String[] args) {
test t = new test();
textfield.setText("Hello");
long a = System.currentTimeMillis();
long c = a;
while (c > a - 1000) {
a = System.currentTimeMillis();
}
textfield.setText("Hello2");
}
static private JTextField textfield;
public test() {
super();
setSize(300, 300);
textfield = new JTextField("Hello1");
add(textfield);
setVisible(true);
}}
上記のコードは正常に実行されています。 1秒後に最初に "Hello"を表示し、次に "Hello2"を表示します。しかし、JFrameフォームでは、 "Hello"の代わりに "Hello2"と表示されます。
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
jTextField1.setText("Hello");
long a = System.currentTimeMillis();
long c = a;
while (c > a - 1000) {
a = System.currentTimeMillis();
}
jTextField1.setText("Hello2");
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(deneme.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(deneme.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(deneme.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(deneme.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new deneme().setVisible(true);
}
});
}
はまた、私はrepaint()
、validate()
とrevalidate()
方法を捜索しました。しかし、私のプロジェクトはJFrameフォームなので、JFrameオブジェクトはありません。したがって、私はこれらの方法を使用することはできません。
お返事ありがとうございます。
「実行していない」とはどういう意味ですか?あなたの現在の行動と期待される行動を説明してください。 –
あなたのプログラムで何をしたいのかをより正確に教えてください。 – whyn0t
@ KrzysztofKosmatka私は、テキストフィールドには "Hello2"しか表示されないことを意味します。私は1秒後に "Hello"、次に "Hello2"と表示することを期待しています。ありがとうございました –