Example usage for javax.swing JOptionPane showMessageDialog

List of usage examples for javax.swing JOptionPane showMessageDialog

Introduction

In this page you can find the example usage for javax.swing JOptionPane showMessageDialog.

Prototype

public static void showMessageDialog(Component parentComponent, Object message) throws HeadlessException 

Source Link

Document

Brings up an information-message dialog titled "Message".

Usage

From source file:Main.java

public static void main(String[] args) {
    final JLabel label = new JLabel();
    int timerDelay = 1000;
    new Timer(timerDelay, new ActionListener() {
        int timeLeft = 5;

        @Override//from   w  w w  .  j  a  v a2 s .co m
        public void actionPerformed(ActionEvent e) {
            if (timeLeft > 0) {
                label.setText("Closing in " + timeLeft + " seconds");
                timeLeft--;
            } else {
                ((Timer) e.getSource()).stop();
                Window win = SwingUtilities.getWindowAncestor(label);
                win.setVisible(false);
            }
        }
    }) {
        {
            setInitialDelay(0);
        }
    }.start();

    JOptionPane.showMessageDialog(null, label);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JTextPane editorPane = new JTextPane();
    editorPane.setSelectedTextColor(Color.red);

    // set content as html
    // editorPane.setContentType("text/html");
    editorPane.setText("<p color='#FF0000'>Cool!</p>");

    // added <u></u> to underlone button
    JButton label = new JButton("button");

    label.setAlignmentY(0.85f);/*from   ww w  .  j ava2s . c om*/

    label.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent e) {

            if (e.isPopupTrigger() || e.getButton() == MouseEvent.BUTTON1) {
                JOptionPane.showMessageDialog(null, "Hello!");
            }
        }
    });

    editorPane.insertComponent(label);
    frame.getContentPane().add(editorPane);
    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JButton button = new JButton("ok");
    button.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            DefaultButtonModel model = (DefaultButtonModel) button.getModel();
            if (model.isEnabled())
                System.out.println("Enabled: true");
            else/*from  www. j  a  v a2 s. c  om*/
                System.out.println("Enabled: false");

            if (model.isArmed())
                System.out.println("Armed: true");
            else
                System.out.println("Armed: false");

            if (model.isPressed())
                System.out.println("Pressed: true");
            else
                System.out.println("Pressed: false");
        }
    });
    JOptionPane.showMessageDialog(null, button);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    String mapUrlPath = "http://www.java2s.com/style/download.png";
    URL mapUrl = new URL(mapUrlPath);
    BufferedImage mapImage = ImageIO.read(mapUrl);
    Image newMapImage = Toolkit.getDefaultToolkit()
            .createImage(new FilteredImageSource(mapImage.getSource(), new GrayToColorFilter(Color.red)));
    ImageIcon mapIcon = new ImageIcon(mapImage);
    ImageIcon newMapIcon = new ImageIcon(newMapImage);

    JPanel imagePanel = new JPanel();
    imagePanel.add(new JLabel(mapIcon));
    imagePanel.add(new JLabel(newMapIcon));

    JOptionPane.showMessageDialog(null, imagePanel);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    URLLabel label = new URLLabel(new URL("http://java2s.com"));

    JOptionPane.showMessageDialog(null, label);

}

From source file:Main.java

public static void main(String[] args) {
    DecimalFormat format = new DecimalFormat("####.##");
    format.setMinimumFractionDigits(2);// w  ww .j a  va2  s.c  o m
    final JFormattedTextField field1 = new JFormattedTextField(format);
    final JFormattedTextField field2 = new JFormattedTextField(format);
    field1.setColumns(15);
    field2.setColumns(15);
    JButton btn = new JButton(new AbstractAction("Multiply by 2") {

        @Override
        public void actionPerformed(ActionEvent e) {
            Number value = (Number) field1.getValue();
            if (value != null) {
                field2.setValue(2 * value.doubleValue());
            }
        }
    });

    JPanel panel = new JPanel();
    panel.add(field1);
    panel.add(btn);
    panel.add(field2);
    JOptionPane.showMessageDialog(null, panel);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    JFileChooser fc = new JFileChooser();
    fc.setMultiSelectionEnabled(true);//  w ww.java 2s .  co m
    fc.setCurrentDirectory(new File("C:\\tmp"));
    JButton btn1 = new JButton("Show Dialog");
    btn1.addActionListener(e -> fc.showDialog(frame, "Choose"));
    JButton btn2 = new JButton("Show Open Dialog");
    btn2.addActionListener(e -> {
        int retVal = fc.showOpenDialog(frame);
        if (retVal == JFileChooser.APPROVE_OPTION) {
            File[] selectedfiles = fc.getSelectedFiles();
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < selectedfiles.length; i++) {
                sb.append(selectedfiles[i].getName());
                sb.append("\n");
            }
            JOptionPane.showMessageDialog(frame, sb.toString());
        }
    });
    JButton btn3 = new JButton("Show Save Dialog");
    btn3.addActionListener(e -> fc.showSaveDialog(frame));
    Container pane = frame.getContentPane();
    pane.setLayout(new GridLayout(3, 1, 10, 10));
    pane.add(btn1);
    pane.add(btn2);
    pane.add(btn3);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    URL url = new URL("http://www.java2s.com/style/download.png");
    final BufferedImage trans = getTransparentImage(ImageIO.read(url), Color.BLACK);
    Runnable r = new Runnable() {
        @Override/*from   w  w  w.j av  a2s. c om*/
        public void run() {
            JLabel gui = new JLabel(new ImageIcon(trans));
            JOptionPane.showMessageDialog(null, gui);
        }
    };
    SwingUtilities.invokeLater(r);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    GraphicsDevice device = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
    device.setFullScreenWindow(frame);//from ww  w . j  a v  a 2s  .com
    device.setDisplayMode(new DisplayMode(800, 600, 32, 60));

    frame.addWindowListener(new WindowAdapter() {
        @Override
        public void windowIconified(WindowEvent we) {
            if (programmatic) {
                programmatic = false;
                frame.setState(JFrame.NORMAL);
            }
        }
    });

    JButton btn = new JButton();
    btn.setText("Btn");
    final JPanel panel = new JPanel();

    panel.add(btn);
    frame.add(panel);

    btn.addActionListener(e -> {
        programmatic = true;
        JOptionPane.showMessageDialog(panel, "Sample");
    });
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JLabel label = new JLabel("java2s.com");
    label.setUI(new VerticalLabelUI(true));

    JOptionPane.showMessageDialog(null, label);

}