S
Sardaukary
I have a very basic swing app with a button that when clicked adds some
text to a JTextArea.
It all works fine until I try to use
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()) to
give the app a Windows XP look and feel.
The program still functions but the button no longer depresses when you
click it. Is this a bug or am I doing something wrong?
am using jre1.5.0_06 and JDK 5
Here's some code to see if anybody else gets this. After you click
Native the Add Text button doesn't animate. Sorry about the formating,
it's late
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.UIManager;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class test extends javax.swing.JFrame implements ActionListener
{
JTextArea messageBox = new JTextArea(20,20);
JButton addText = new JButton("Add Text");
JButton changeThemexp = new JButton("Native");
JButton changeThemecross = new JButton("X platform");
public test()
{
super("Test");
setDefaultCloseOperation(EXIT_ON_CLOSE);
messageBox.setLineWrap(true);
JScrollPane scrollPane= new JScrollPane (messageBox);
addText.addActionListener(this);
changeThemexp.addActionListener(this);
changeThemecross.addActionListener(this);
JPanel panel = new JPanel();
panel.add(addText);
panel.add(changeThemexp);
panel.add(changeThemecross);
panel.add(scrollPane);
add(panel);
pack();
setResizable(false);
setVisible(true);
}
public void addText (String texttoadd)
{
messageBox.append(texttoadd);
}
public void actionPerformed(ActionEvent evt)
{
if (evt.getSource()== addText)addText("Testing\n");
if (evt.getSource()== changeThemexp)
try
{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch (Exception e) {};repaint();
if (evt.getSource()== changeThemecross)
try
{
UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
}
catch (Exception e) {};repaint();
}
;
public static void main(String[] args)
{
test gui = new test();
}
}
text to a JTextArea.
It all works fine until I try to use
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()) to
give the app a Windows XP look and feel.
The program still functions but the button no longer depresses when you
click it. Is this a bug or am I doing something wrong?
am using jre1.5.0_06 and JDK 5
Here's some code to see if anybody else gets this. After you click
Native the Add Text button doesn't animate. Sorry about the formating,
it's late
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.UIManager;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class test extends javax.swing.JFrame implements ActionListener
{
JTextArea messageBox = new JTextArea(20,20);
JButton addText = new JButton("Add Text");
JButton changeThemexp = new JButton("Native");
JButton changeThemecross = new JButton("X platform");
public test()
{
super("Test");
setDefaultCloseOperation(EXIT_ON_CLOSE);
messageBox.setLineWrap(true);
JScrollPane scrollPane= new JScrollPane (messageBox);
addText.addActionListener(this);
changeThemexp.addActionListener(this);
changeThemecross.addActionListener(this);
JPanel panel = new JPanel();
panel.add(addText);
panel.add(changeThemexp);
panel.add(changeThemecross);
panel.add(scrollPane);
add(panel);
pack();
setResizable(false);
setVisible(true);
}
public void addText (String texttoadd)
{
messageBox.append(texttoadd);
}
public void actionPerformed(ActionEvent evt)
{
if (evt.getSource()== addText)addText("Testing\n");
if (evt.getSource()== changeThemexp)
try
{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch (Exception e) {};repaint();
if (evt.getSource()== changeThemecross)
try
{
UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
}
catch (Exception e) {};repaint();
}
;
public static void main(String[] args)
{
test gui = new test();
}
}