4 import java
.awt
.event
.ActionEvent
;
5 import java
.text
.MessageFormat
;
6 import java
.util
.ResourceBundle
;
8 public class FormPreviewFrame
{
9 private JComponent myComponent
;
10 private static final ResourceBundle ourBundle
= ResourceBundle
.getBundle("RuntimeBundle");
12 // Note: this class should not be obfuscated
14 public static void main(String
[] args
) {
15 FormPreviewFrame f
= new FormPreviewFrame();
17 JFrame frame
= new JFrame(ourBundle
.getString("form.preview.title"));
18 frame
.setContentPane(f
.myComponent
);
19 frame
.setDefaultCloseOperation(JFrame
.EXIT_ON_CLOSE
);
22 final JMenuBar menuBar
= new JMenuBar();
23 frame
.setJMenuBar(menuBar
);
25 final JMenu menuFile
= new JMenu(ourBundle
.getString("form.menu.preview"));
26 menuFile
.setMnemonic(ourBundle
.getString("form.menu.preview.mnemonic").charAt(0));
27 menuFile
.add(new JMenuItem(new MyPackAction(frame
)));
28 menuFile
.add(new JMenuItem(new MyExitAction()));
29 menuBar
.add(menuFile
);
31 final JMenu viewMenu
= new JMenu(ourBundle
.getString("form.menu.laf"));
32 viewMenu
.setMnemonic(ourBundle
.getString("form.menu.laf.mnemonic").charAt(0));
33 menuBar
.add(viewMenu
);
35 final UIManager
.LookAndFeelInfo
[] lafs
= UIManager
.getInstalledLookAndFeels();
36 for(int i
= 0; i
< lafs
.length
; i
++){
37 viewMenu
.add(new MySetLafAction(frame
, lafs
[i
]));
41 Dimension screenSize
= Toolkit
.getDefaultToolkit().getScreenSize();
42 frame
.setLocation((screenSize
.width
- frame
.getWidth())/2, (screenSize
.height
- frame
.getHeight())/2);
43 frame
.setVisible(true);
46 private static final class MyExitAction
extends AbstractAction
{
47 public MyExitAction() {
48 super(ourBundle
.getString("form.menu.file.exit"));
51 public void actionPerformed(final ActionEvent e
) {
56 private static final class MyPackAction
extends AbstractAction
{
57 private final JFrame myFrame
;
59 public MyPackAction(final JFrame frame
) {
60 super(ourBundle
.getString("form.menu.view.pack"));
64 public void actionPerformed(final ActionEvent e
) {
69 private static final class MySetLafAction
extends AbstractAction
{
70 private final JFrame myFrame
;
71 private final UIManager
.LookAndFeelInfo myInfo
;
73 public MySetLafAction(final JFrame frame
, final UIManager
.LookAndFeelInfo info
) {
74 super(info
.getName());
79 public void actionPerformed(ActionEvent e
) {
81 UIManager
.setLookAndFeel(myInfo
.getClassName());
82 SwingUtilities
.updateComponentTreeUI(myFrame
);
83 Dimension prefSize
= myFrame
.getPreferredSize();
84 if(prefSize
.width
> myFrame
.getWidth() || prefSize
.height
> myFrame
.getHeight()){
89 JOptionPane
.showMessageDialog(
91 MessageFormat
.format(ourBundle
.getString("error.cannot.change.look.feel"), new Object
[] {exc
.getMessage()}),
92 ourBundle
.getString("error.title"),
93 JOptionPane
.ERROR_MESSAGE