私は彼らのルック&フィールを変更したいいくつかのウィジェットで、コマンドラインでアプリケーションを作っ動作しません:クラスのコンストラクタにのみウィジェットを命じる 変更スイングL&Fはよく
java -Dswing.defaultlaf=com.sun.java.swing.plaf.windows.WindowsLookAndFeel LookAndFeelAppl
が、呼び出された後
L & Fを変更しますが、別の方法で作成したものはありません。また、JFrame自体は変更されません。パブリッククラスLookAndFeelApplはJFrameを拡張します { プライベートJLabelラベル; プライベートJButtonボタン。
public LookAndFeelAppl()
{
super("Look And Feel Demo");
setLayout(null);
final UIManager.LookAndFeelInfo plaf[] = UIManager.getInstalledLookAndFeels();
JLabel lable_laf = new JLabel("Choose L&F:");
final JComboBox cb = new JComboBox();
createOtherGUI();
cb.addItemListener(new ItemListener()
{
public void itemStateChanged(ItemEvent e)
{
int ix = cb.getSelectedIndex();
try
{
UIManager.setLookAndFeel(plaf[ix].getClassName());
SwingUtilities.updateComponentTreeUI(LookAndFeelAppl.this);
}
catch (Exception ex)
{
}
}
});
// HERE IS THE PROBLEM!!!! THIS LOOP GOES BEFORE
// THE ITEMLISTENER BECAUSE WHEN I ADD ITEMS AN ITEMEVENT
// IS RAISED THAT SET AGAIN THE L&F WITH setLookAndFeel!!!
for (int i = 0, n = plaf.length; i < n; i++)
{
cb.addItem(plaf[i].getName());
}
//--------------------------------------------------------
add(lable_laf);
add(cb);
lable_laf.setBounds(10, 10, 150, 25);
cb.setBounds(10, 35, 150, 25);
}
public void createOtherGUI()
{
button = new JButton("BUTTON!!!!");
add(button);
button.setBounds(300, 45, 150, 35);
}
public static void main(String args[])
{
LookAndFeelAppl window = new LookAndFeelAppl();
window.setSize(1000, 700);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setVisible(true);
window.setLocationRelativeTo(null);
}
}
いくつかのスクリーンショットの書式は奇妙ですが、あなたのアイデアを得ますか? –
したがって、createOtherGUI()は正常に動作しません。それがあればそれは助けになるでしょう。 – josefx
コンパイルされません。あなたのクラスは 'JFrame'を拡張しますが、コードスニペットにこれを追加するのを忘れましたか? – Qwerky