On Mon, 09 Sep 2013 12:14:32 +0200
Michael Vehrs <michael.bursc...@gmx.de> wrote:
> This isn't pretty, but it does work:
> 
>      public boolean showConfirmDialog(String text, String okText, String 
> cancelText) {
>          String[] options = new String[] {
>              Messages.message(okText),
>              Messages.message(cancelText)
>          };
>          int ret = JOptionPane.showInternalOptionDialog(this, 
> Messages.message(text),
>                                                         "option test",
> JOptionPane.PLAIN_MESSAGE,
> JOptionPane.YES_NO_OPTION,
>                                                         null, options, 
> okText);
>          return (ret == JOptionPane.YES_OPTION || ret == 
> JOptionPane.OK_OPTION);
>      }

I had a bit of a play with this.  Adding the icon is trivial:

    public boolean showConfirmDialog(Tile tile, String text, ImageIcon icon,
                                     String okText, String cancelText) {
        String[] options = new String[] {
            Messages.message(okText),
            Messages.message(cancelText)
        };
        int ret = JOptionPane.showInternalOptionDialog(this, 
            Messages.message(text), "option test",
            JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE,
            icon, options, options[0]);
        return ret == JOptionPane.YES_OPTION || ret == JOptionPane.OK_OPTION;
    }

...but I can not find a good way of getting rid of the dialog box
title/decoration.  The following is sort of equivalent:

        ...
        JOptionPane pane = new JOptionPane(Messages.message(text),
            JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION,
            icon, options, options[0]);
        JDialog dialog = pane.createDialog(this, "option test");
        dialog.setModal(true);
        dialog.setVisible(true);
        Object value = pane.getValue();
        return options[0].equals(value);

... and gives you access to the JDialog, allowing direct control of
modality which will be needed.  However you are not allowed to call
setDecorated(false), apparently because it is already visible.  WTF.

Cheers,
Mike Pope

Attachment: signature.asc
Description: PGP signature

------------------------------------------------------------------------------
LIMITED TIME SALE - Full Year of Microsoft Training For Just $49.99!
1,500+ hours of tutorials including VisualStudio 2012, Windows 8, SharePoint
2013, SQL 2012, MVC 4, more. BEST VALUE: New Multi-Library Power Pack includes
Mobile, Cloud, Java, and UX Design. Lowest price ever! Ends 9/20/13. 
http://pubads.g.doubleclick.net/gampad/clk?id=58041151&iu=/4140/ostg.clktrk
_______________________________________________
Freecol-developers mailing list
Freecol-developers@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/freecol-developers

Reply via email to