Search code examples
eclipseswingdialogjoptionpane

JOptionPane.showInputDialog same style with the rest of Eclipse


So I'm trying to get the Dialog have the same style as the rest of the Eclipse. This input is triggered when a button on a menu is pressed. Here is my code right now , but the Dialog looks the same with null instead of (Component) win as parameter.

    // JFrame frame = new JFrame ("Something");
    IWorkbench wb = PlatformUI.getWorkbench();
    IWorkbenchWindow win = wb.getActiveWorkbenchWindow();

    while (b != true) {
         userInput = (String) JOptionPane.showInputDialog((Component) win, "Entersomething", "GDB Server Connection Port:", JOptionPane.DEFAULT_OPTION, null,null,2345);
            if (userInput != null && userInput.matches("[0-9]+")) {
                b = true; }
            else {
                JOptionPane.showMessageDialog(Component) win, "Please enter valid input","Error",JOptionPane.WARNING_MESSAGE);
            }
    }
    return userInput ;

Solution

  • Use LookAndFeel to have same style in whole application instead:

     UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    

    EDIT:

    Have a look at this then:

    http://www.programcreek.com/java-api-examples/index.php?api=org.eclipse.swt.widgets.MessageBox

    http://www.java2s.com/Code/Java/SWT-JFace-Eclipse/DialogExamples.htm

    http://www.vogella.com/tutorials/EclipseDialogs/article.html