Synth Look And Feel With UIManager.getDefaults()
Please guide me on this problem.
Why the UIManager.getDefaults().getFont("TextField.font") is returning null with Synth Look and feel.?
I have synth.xml file as
<synth>
<style id="textfield">
<state>
<color value="pink" type="BACKGROUND"/>
</state>
<font name="Lucida" size="12"/>
<insets top="5" bottom="6" right="7" left="6"/>
</style>
<bind style="textfield" type="region" key="TextField"/>
</synth>
And test java file is TestSynth.java
import java.awt.FlowLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.UIManager;
import javax.swing.plaf.synth.SynthLookAndFeel;
import javax.swing.plaf.*;
public class TestSynth extends JFrame {
public TestSynth() {
super("TestSynth");
try{
SynthLookAndFeel laf = new SynthLookAndFeel();
laf.load(TestSynth.class.getResourceAsStream("synth.xml"), TestSynth.class);
UIManager.setLookAndFeel(laf);
} catch (Exception e) {
System.err.println(e);
}
// why this is throwing a NullPointerException.??
try{
FontUIResource defaultFont = new FontUIResource(UIManager.getDefaults().getFont(
"TextField.font"));
}catch(Exception e){
e.printStackTrace();
}
// this is null thats why the above is throwing nullpointer .. but why it is null?
System.out.println(UIManager.getDefaults().getFont("Label.font"));
JLabel label = new JLabel("Enter name : ");
JTextField textField = new JTextField(30);
setLayout(new FlowLayout());
getContentPane().add(label);
getContentPane().add(textField);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(500,500);
setLocation(200,100);
}
public static void main(String[] args) {
TestSynth testSynth = new TestSynth();
testSynth.setVisible(true);
}
}
Please guide on this issue..!
Its urgent..!
Thanks in advance..!
Amit

