私はJButtonの背景色をツイニングしようとしていますが、動作しているのは「スリープ」だけです。JComponentの背景色をどのようにツインクリングするのですか?
マイコード:
@Override
public void actionPerformed(ActionEvent e){
if(!empty){
}else{
myButton.setBackground(Color.RED);
try {TimeUnit.MILLISECONDS.sleep(200);} catch (InterruptedException e2){}
myButton.setBackground(Color.LIGHT_GRAY);
try {TimeUnit.MILLISECONDS.sleep(200);} catch (InterruptedException e1) {}
myButton.setBackground(Color.RED);
try {TimeUnit.MILLISECONDS.sleep(200);} catch (InterruptedException e1) {}
myButton.setBackground(Color.LIGHT_GRAY);
}
}
}
EDIT: は全体のコード、非常に多くの行を転記することはできません。 ボタンがGridBagLayoutの内側にある:
myButton= new Jbutton("Button!");
myButton.setBackground(Color.White);
myButton.setHorizontalAlignment(JTextField.CENTER);;
myButton.setForeground(Color.black);
GridBagConstraints gbc_myButton = new GridBagConstraints();
gbc_myButton.fill = GridBagConstraints.BOTH;
gbc_myButton.gridx = 0;
gbc_myButton.gridy = 1;
gbc_myButton.gridwidth=3;
panel.add(myButton, gbc_myButton);
EDIT 2: 私はちょうどそれが(または任意の遅延/スリープなし)、実行時に任意の色を設定していない把握します。
はあなたが何を意味するかsetBackgroundの呼び出しによって背景を変更しませんか? – ItamarG3
遅延は機能しますが、色は変わりません。 – tomyforever
a)200ミリ秒は非常に短いですが、スリープ時間を長くしてください。 b)あなたはそのコードをループしていますか? – ItamarG3