| Author |
How to Dialog appear with look & feels CrossPlatform?
|
Thang Nguyen Cao
Greenhorn
Joined: Nov 17, 2004
Posts: 1
|
|
Why this follow code don't appear with L&Fs CrossPlatform?It's still appear with the title bar of OS that I use ( Windows XP). package myprojects.icondialogswing; import java.awt.*; import java.awt.event.*; import javax.swing.*; /* * IconDialogSwing.java * * Created on November 6, 2004, 12:07 AM */ /** * * @author thangcan */ public class IconDialogSwing extends JPanel { ImageIcon icon = createImageIcon("icon/middle.gif"); JFrame frame; String iconDesc = "A JOptionPane has its choice of icons"; /** Creates a new instance of IconDialogSwing */ public IconDialogSwing() { super(new BorderLayout()); JPanel iconPanel = createIconDialog(); JLabel label = new JLabel("Click the \"Show it!\" button" + " to bring up the selected dialog.", JLabel.CENTER); iconPanel.setBorder(BorderFactory.createEmptyBorder(20,20,5,20)); this.add(iconPanel,BorderLayout.PAGE_START); this.add(label,BorderLayout.PAGE_END); this.setBorder(BorderFactory.createEmptyBorder(10,10,10,10)); } protected static ImageIcon createImageIcon(String path) { java.net.URL imgURL = IconDialogSwing.class.getResource(path); if (imgURL != null) { return new ImageIcon(imgURL); } else { System.err.println("Couldn't find file: " + path); return null; } } private JPanel create2ColPane(String description, JRadioButton[] radioButtons, JButton showButton) { JLabel label = new JLabel(description); int numPerColumn = radioButtons.length/2; JPanel grid = new JPanel(new GridLayout(0, 2)); for (int i = 0; i < numPerColumn; i++) { grid.add(radioButtons); grid.add(radioButtons[i + numPerColumn]); } JPanel box = new JPanel(); box.setLayout(new BoxLayout(box, BoxLayout.PAGE_AXIS)); box.add(label); grid.setAlignmentX(0.0f); box.add(grid); JPanel pane = new JPanel(new BorderLayout()); pane.add(box, BorderLayout.PAGE_START); pane.add(showButton, BorderLayout.PAGE_END); return pane; } private JPanel createIconDialog() { JButton showItButton = null; final int numButtons = 6; JRadioButton[] radioButtons = new JRadioButton[numButtons]; final ButtonGroup group = new ButtonGroup(); final String plainCommand = "plain"; final String infoCommand = "info"; final String questionCommand = "question"; final String errorCommand = "error"; final String warningCommand = "warning"; final String customCommand = "custom"; radioButtons[0] = new JRadioButton("Plain (no icon)"); radioButtons[0].setActionCommand(plainCommand); radioButtons[1] = new JRadioButton("Information icon"); radioButtons[1].setActionCommand(infoCommand); radioButtons[2] = new JRadioButton("Question icon"); radioButtons[2].setActionCommand(questionCommand); radioButtons[3] = new JRadioButton("Error icon"); radioButtons[3].setActionCommand(errorCommand); radioButtons[4] = new JRadioButton("Warning icon"); radioButtons[4].setActionCommand(warningCommand); radioButtons[5] = new JRadioButton("Custom icon"); radioButtons[5].setActionCommand(customCommand); for (int i = 0; i < numButtons; i++) { group.add(radioButtons); } radioButtons[0].setSelected(true); showItButton = new JButton("Show it!"); showItButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String command = group.getSelection().getActionCommand(); //no icon if (command == plainCommand) { JOptionPane.showMessageDialog(frame, "Eggs aren't supposed to be green.", "A plain message", JOptionPane.PLAIN_MESSAGE); //information icon } else if (command == infoCommand) { JOptionPane.showMessageDialog(frame, "Eggs aren't supposed to be green.", "Inane informational dialog", JOptionPane.INFORMATION_MESSAGE); //question icon } else if (command == questionCommand) { JOptionPane.showMessageDialog(frame, "You shouldn't use a message dialog " + "(like this)\n" + "for a question, OK?", "Inane question", JOptionPane.QUESTION_MESSAGE); //error icon } else if (command == errorCommand) { JOptionPane.showMessageDialog(frame, "Eggs aren't supposed to be green.", "Inane error", JOptionPane.ERROR_MESSAGE); //warning icon } else if (command == warningCommand) { JOptionPane.showMessageDialog(frame, "Eggs aren't supposed to be green.", "Inane warning", JOptionPane.WARNING_MESSAGE); //custom icon } else if (command == customCommand) { JOptionPane.showMessageDialog(frame, "Eggs aren't supposed to be green.", "Inane custom dialog", JOptionPane.INFORMATION_MESSAGE, icon); } } }); return create2ColPane(iconDesc + ":", radioButtons, showItButton); } private static void createAndShowGUI() { JFrame.setDefaultLookAndFeelDecorated(true); JFrame frame = new JFrame("IconDialogSwing"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); IconDialogSwing newContentPane = new IconDialogSwing(); newContentPane.setOpaque(true); //content panes must be opaque frame.setContentPane(newContentPane); frame.pack(); frame.setVisible(true); } public static void main(String[] args) { javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { createAndShowGUI(); } }); } } Though I inserted a snip code setDefaultLookAndFeelDecorated(true).Why 's that??? When I wrote a app that extends JDialog, I also used method setContentPane(contenPane) which contentPane = new JOptionPane(...) and method setDefaultLookAndFeelDecorated(true), this app appear with L&Fs CrossPlatform? Help me.
|
 |
 |
I agree. Here's the link: jrebel
|
|
subject: How to Dialog appear with look & feels CrossPlatform?
|
|
|