LookAndFeelインターフェイスのコピーをファイルにシリアライズする必要があります。シリアライズ可能なLookAndFeel - ClassCastException
public class SerializableLookAndFeel extend LookAndFeel implement Serializable {
public String getID() {
return "";
}
public String getDescription() {
return "";
}
public String getName() {
return "";
}
public boolean isSupportedLookAndFeel() {
return false;
}
public boolean isNativeLookAndFeel() {
return false;
}
}
ランタイム私はスレッドで
例外を取得しますが、 "メイン" とjava.lang.ClassCastException: javax.swing.plaf.metal.MetalLookAndFeel結果として、私は次のコードを書いています test.SerializableLookAndFeel
にキャストすることはできません私ははMetalLookAndFeelを拡張しようとしたが、実行時に、私はClassCastExceptionが取得します。
どうすればLookAndFeelをファイルにシリアル化できますか?パラメータとしてSet the Look and Feelへ
私がやろうとしていることは、私のPCから私の現在の外観を取得し、起動するたびにこの設定をアプリケーションにロードさせることです。だから、私はバイナリオブジェクトとして保存することに決めました。しかし、あなたが示唆していることをするには問題があります - あなたはBasicLookAndFeelのようなことはできませんlookAndFeel = UIManager.getLookAndFeel(); IDEは私をさせません。 – ilja
'UIManager.getLookAndFeel()'は、LookAndFeelを返します。これは、Abstractクラスです。あなたはコードがうまくいくはずです、キャストしようとしましたか? 'BasicLookAndFeel lookAndFeel =(BasicLookAndFeel)UIManager.getLookAndFeel();'どのIDEを使用していますか?実行できるコードを投稿できますか?私はコードを見ることなく大いに役立つことはできません。また、問題が解決しない場合は、デバッガを見て、 'getLookAndFeel()'が何を返すかを見てください。 – Ali
'public static void main(String [] args)例外をスローする{ JFrame frame = new JFrame(" Test "); frame.setSize(600、400); TextArea textArea = new TextArea(20、10); frame.add(textArea); frame.setVisible(true); BasicLookAndFeel blaf =(BasicLookAndFeel)UIManager.getLookAndFeel(); s(blaf); } パブリックstatic void(BasicLookAndFeel blaf){ try { FileOutputStream fout = new FileOutputStream( "basiclook.dat"); ObjectOutputStream oos =新しいObjectOutputStream(fout)。 oos.writeObject(basicLookAndFeel); oos.close(); } catch(例外e){ e.printStackTrace(); } } ' java.io.NotSerializableException:java.lang.Object.IDEAを使用します – ilja