Re: Type conversion for reference types?
Peter Duniho wrote:
I made a specific choice to try to avoid Swing. The program I'm writing
isn't going to use any advanced controls anyway, and I'd prefer that
what controls I do use be using native controls on each platform, to
retain native look-and-feel.
(As an aside, the three main APIs I looked at were AWT, Swing, and SWT.
SWT has so far produces far superior graphical rendering for me, but I'm
put off by the need to deliver a separate library for each platform I
want to support. With AWT and Swing, if a recent enough Java is
installed, the same Java program should run on any platform, as I
understand it. From what I've read, Swing reimplements all of the
controls and always will look the same regardless of the host OS).
Have you tried playing with look and feel.
The demo program below illustrates.
Arne
=============================================
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class MultiLookAndFeel extends JFrame implements ActionListener {
private JButton windows = new JButton("Windows");
private JButton motif = new JButton("Motif");
private JButton metal1 = new JButton("Metal/ocean");
private JButton metal2 = new JButton("Metal/steel");
private JButton gtk = new JButton("GTK");
private JButton java = new JButton("Java");
private JButton system = new JButton("System");
public MultiLookAndFeel() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
getContentPane().setLayout(new GridLayout(7, 1));
windows.addActionListener(this);
getContentPane().add(windows);
motif.addActionListener(this);
getContentPane().add(motif);
metal1.addActionListener(this);
getContentPane().add(metal1);
metal2.addActionListener(this);
getContentPane().add(metal2);
//gtk.addActionListener(this);
getContentPane().add(gtk);
java.addActionListener(this);
getContentPane().add(java);
system.addActionListener(this);
getContentPane().add(system);
pack();
}
public void actionPerformed(ActionEvent e) {
try {
if(e.getSource() == windows) {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
} else if(e.getSource() == motif) {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
} else if(e.getSource() == metal1) {
javax.swing.plaf.metal.MetalLookAndFeel.setCurrentTheme(new
javax.swing.plaf.metal.OceanTheme());
UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
} else if(e.getSource() == metal2) {
javax.swing.plaf.metal.MetalLookAndFeel.setCurrentTheme(new
javax.swing.plaf.metal.DefaultMetalTheme());
UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
} else if(e.getSource() == gtk) {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
} else if(e.getSource() == java) {
UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
} else if(e.getSource() == system) {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
} catch (ClassNotFoundException e1) {
e1.printStackTrace();
} catch (InstantiationException e1) {
e1.printStackTrace();
} catch (IllegalAccessException e1) {
e1.printStackTrace();
} catch (UnsupportedLookAndFeelException e1) {
e1.printStackTrace();
}
SwingUtilities.updateComponentTreeUI(this);
pack();
}
public static void main(String[] args) {
MultiLookAndFeel f = new MultiLookAndFeel();
f.setVisible(true);
}
}