Võ Văn Hải's blog

Chỉ có một điều tuyệt đối đó là mọi thứ đều tương đối…

Chuyển đổi giao diện thành “Motif look and feel” trong Java 6

import java.awt.Dimension;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.JTree;
import javax.swing.UIManager;

public class GTKLookAndFeelDemo {
public static void main(String[] args) {
try {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
} catch (Exception e) {
e.printStackTrace();
}
JLabel label = new JLabel("Label");
JTextField field = new JTextField("htp://vovanhai.wordpress.com");
JList list = new JList(new String[] { "A", "B", "C" });
JScrollPane listPane = new JScrollPane(list);
listPane.setPreferredSize(new Dimension(250, 100));

JScrollPane treePane = new JScrollPane(new JTree());
treePane.setPreferredSize(new Dimension(250, 100));
JButton button = new JButton("Click me");

JPanel cp = new JPanel();
cp.add(label);
cp.add(field);
cp.add(listPane);
cp.add(treePane);
cp.add(button);

JFrame frame = new JFrame();
frame.setTitle("Windows Look and Feel Demo");
frame.setPreferredSize(new Dimension(280, 300));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setContentPane(cp);
frame.pack();
frame.setVisible(true);

}
}

Kết quả như hình
https://vovanhai.files.wordpress.com/2008/09/motiflaf.png

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: