JDialog with options and custom buttons

I can't seem to find a builder for custom buttons and drop-down menu items. I wanted to do was add custom buttons this text simply nothing complicated. 'Connect' and 'Cancel '.
/**
 * Dialog window for new connection.
 */
protected String NewConnectionDialog()
{
     Window win = SwingUtilities.getWindowAncestor(mainPanel);
     String[] databases = {"Oracle", "Access", "MySQL", "PostgreSQL"};
     Object[] options = {"Connect", "Cancel"};

     String s = (String)JOptionPane.showInputDialog( win, 
               "Select Database:", "New Connection Wizard.", 
               JOptionPane.OK_CANCEL_OPTION, icon, databases, 
               "MySQL" );

     String nullStr  = ""; // no exceptions thanks
     return (s != null ? s.toUpperCase() : nullStr);
}

javax.swing.JOptionPane.showOptionDialog ()...

JPanel pea = new JPanel();
JLabel jl = new JLabel("Select DB");
JComboBox jcb = new JComboBox(...stuff here..);
pea.ad(jl);
pea.add(jcb);

JButton conButton = new JButton("Connect");
Object[] buttonRowObjects = new Object[] {
  conButton, "Cancel"
};

int result = JOptionPane.showOptionDialog(
  Component parentComponent,
  Object message,//<- pea right here
  String title,
  int optionType,
  int messageType,
  Icon icon,
  Object[] options,//<- buttonRowObjects here
  Object initialValue
);

There now, your patience has paid off. And don't forget to eat your vegetables.

Tags: Java

Similar Questions

  • Problem with fieldChanged() and custom button field

    Hello

    I created a custom button class by extending LabelField.  I chose LabelField over field because the LabelField contains desirable properties that are already being implemented.  The only problem I'm having has to do with the change listener.  It seems to 'steal' the event click on other areas in my application.

    For example, when I click on the custom button, a popupscreen with a listfield opens. When I click on an item in the listfield, then the fieldChanged() of custom button is called again...

    Can you see anything wrong with my code?

    package com.rantnetwork.fields;
    
    import com.rantnetwork.app.Constants;
    import net.rim.device.api.system.Display;
    import net.rim.device.api.ui.Color;
    import net.rim.device.api.ui.Field;
    import net.rim.device.api.ui.Font;
    import net.rim.device.api.ui.Graphics;
    import net.rim.device.api.ui.Ui;
    import net.rim.device.api.ui.XYEdges;
    import net.rim.device.api.ui.component.LabelField;
    import net.rim.device.api.ui.decor.BackgroundFactory;
    import net.rim.device.api.ui.decor.BorderFactory;
    
    public class CustomButtonField extends LabelField {
    
        private boolean highlighted = false;
    
        public CustomButtonField(String text, long style) {
            super(text, style | Field.FOCUSABLE | LabelField.ELLIPSIS);
    
            setPadding(10, 0, 10, 5);
    
            setFont(Font.getDefault().derive(Font.BOLD,
                    Constants.DEFAULT_FONT_SIZE, Ui.UNITS_pt));
    
            setBackground(BackgroundFactory.createLinearGradientBackground(
                    0x163d7c, 0x163d7c, 0x03162d, 0x03162d));
            setBorder(BorderFactory
                    .createBevelBorder(new XYEdges(1, 1, 1, 1), new XYEdges(
                            Color.BLACK, Color.BLACK, Color.BLACK, Color.BLACK),
                            new XYEdges(Color.BLACK, Color.BLACK, Color.BLACK,
                                    Color.BLACK)));
    
        }
    
        public int getPreferredWidth() {
            return Display.getWidth() / 3;
        }
    
        protected void paint(Graphics graphics) {
            graphics.setColor(Color.WHITE);
            super.paint(graphics);
        }
    
        protected void drawFocus(Graphics graphics, boolean on) {
            // Do nothing
        }
    
        protected boolean navigationClick(int status, int time) {
            fieldChangeNotify(1);
            return true;
        }
    
        protected void onFocus(int direction) {
            if (!highlighted) {
                setBackground(BackgroundFactory.createLinearGradientBackground(
                        0x4bb7df, 0x4bb7df, 0x1b96da, 0x1b96da));
                setBorder(BorderFactory.createBevelBorder(new XYEdges(1, 1, 1, 1),
                        new XYEdges(Color.BLACK, Color.BLACK, Color.BLACK,
                                Color.BLACK), new XYEdges(Color.BLACK, Color.BLACK,
                                Color.BLACK, Color.BLACK)));
            }
        }
    
        protected void onUnfocus() {
            if (!highlighted) {
                setBackground(BackgroundFactory.createLinearGradientBackground(
                        0x163d7c, 0x163d7c, 0x03162d, 0x03162d));
                setBorder(BorderFactory.createBevelBorder(new XYEdges(1, 1, 1, 1),
                        new XYEdges(Color.BLACK, Color.BLACK, Color.BLACK,
                                Color.BLACK), new XYEdges(Color.BLACK, Color.BLACK,
                                Color.BLACK, Color.BLACK)));
            }
        }
    
        public void showHighlighted(boolean focus) {
            if (focus) {
                highlighted = true;
                setBackground(BackgroundFactory.createLinearGradientBackground(
                        0x4bb7df, 0x4bb7df, 0x1b96da, 0x1b96da));
                setBorder(BorderFactory.createBevelBorder(new XYEdges(1, 1, 1, 1),
                        new XYEdges(Color.BLACK, Color.BLACK, Color.BLACK,
                                Color.BLACK), new XYEdges(Color.BLACK, Color.BLACK,
                                Color.BLACK, Color.BLACK)));
            } else {
                highlighted = false;
                setBackground(BackgroundFactory.createLinearGradientBackground(
                        0x163d7c, 0x163d7c, 0x03162d, 0x03162d));
                setBorder(BorderFactory.createBevelBorder(new XYEdges(1, 1, 1, 1),
                        new XYEdges(Color.BLACK, Color.BLACK, Color.BLACK,
                                Color.BLACK), new XYEdges(Color.BLACK, Color.BLACK,
                                Color.BLACK, Color.BLACK)));
            }
            invalidate();
        }
    
        public boolean isHighlighted() {
            return highlighted;
        }
    
    }
    

    behrk2 wrote:

    Now, I'm not sure why customButton.setText (calling) would trigger the fieldChanged().  Can anyone think of a reason why he can do?

    Thank you!

    Can you think of a reason why we can't do that? The field has changed, after all! Of course, the context (second argument to fieldChanged) will be PROGRAMMATIC in this case, that might be a pretty good indication for you. But not invoke fieldChanged at all would be wrong.

    This is why I don't like the idea of extending LabelField and not just the field for your custom badges - you have much less control over his behavior. If you want an example showing how to create abstract off-screen buttons, take a look at BaseButtonField and his descendants in managers, fields and advanced buttons.

  • I'm restaurant a 2003 server machine work. She asked a gentleman confirmation with 'Yes' and 'no' buttons. I need a command that can answer that the dialogue when the schedule runs.

    Hi all

    I'm restaurant work that stops a service from one application to the 2003 server machine. She asked a gentleman confirmation with 'Yes' and 'no' buttons. I need a command that can answer that dialogue with 'Yes' at the time of the schedule runs.

    Thank you

    Arun

    Hello

    Are you referring to Windows Server 2003?

    The question you have posted is related to professional level support. Please visit the link below to find a community that will support what ask you:

    http://social.technet.Microsoft.com/forums/en-us/category/WindowsServer

  • Navigation in both sense between the anchor points with "prev" and "next buttons?"

    Hi all

    I'm working on a horizontal presentation site that has anchors on each part. That the user scroll, he snaps to each anchor point. It works fine with just the mouse wheel, but I wish I had previous buttons and following which allow easy navigation between points. I know I can have buttons to jump to say on each article has > B > C and then C > B >, but it's a simple "prev" and "next" buttons that are pinned to the page as a whole. Then, as the page scrolls from left to right, the buttons remain in place. Is it possible to have them just go to previous and next in the line, rather than linking a button to anchor point A, B, C, etc.?

    NEW WIDGET! Navigation in both sense between the anchor points with "prev" and "next" buttons http://goo.GL/TMbZRc

  • Scroll and custom button image

    Hi all

    I'm having some difficulty with it.

    I have now managed to get a scrolling image downloaded from a url.

    I now place buttons above the image scroll, previous and next buttons.  But I can't seem to the paint without knocking the image scrolling.

    Any ideas on how I can achieve this.  If I do a this.add in the constructor, it gets ignored because I replaced the painting.

    Real novice so the pointers/code examples would be fantastic.

    Cheers all, you're really a helpful bunch!

    /* * OldImage.java * * © , 2003-2008 * Confidential and proprietary. */
    
    package PageSuite;
    
    import java.io.*;import javax.microedition.io.*;import net.rim.device.api.system.*;import net.rim.device.api.ui.*;import net.rim.device.api.ui.component.*;import net.rim.device.api.ui.container.*;import net.rim.device.api.system.Bitmap;import net.rim.device.api.ui.Graphics;import net.rim.device.api.ui.UiApplication;import net.rim.device.api.ui.component.Dialog;import net.rim.device.api.ui.container.MainScreen;import net.rim.device.api.util.DataBuffer;import net.rim.device.api.util.ByteVector;import net.rim.device.api.util.*;import java.util.*;import net.rim.device.api.i18n.*;import javax.microedition.lcdui.Image;
    
    class OldImage extends MainScreen {                private static final int HORZ_SCROLL_FACTOR     = 10;          private static final int VERT_SCROLL_FACTOR     = 10;
    
             Bitmap bitmap;            int left = 0;          int top = 0;           int maxLeft = 0;               int maxTop = 0;
    
                   public OldImage() {
    
                            StreamConnection stream = null;                        InputStream in = null;                        synchronized(this)                        {                        try                        {                        stream = (StreamConnection)Connector.open("http://www.image.com/get_image.aspx?eid=032cf610-8918-425b-a4d9-441fa9468f23&w=" + Graphics.getScreenWidth() + "&pnum=1");                        in = stream.openInputStream();                        }                        catch(Exception e)                        {                        }                        }                        try                        {                        // Extract the data from the input stream.                        byte[] data = new byte[in.available()];                        try                        {                        DataBuffer db = new DataBuffer();                        int chunk = 0;                        while ( -1 != (chunk = in.read(data)))                        {                        db.write(data, 0, chunk);                        }                        in.close();                        // Here is ur image in byte format.                        data = db.getArray();                        }                        catch(Exception e)                        {                        }
    
                            EncodedImage jpegPic = EncodedImage.createEncodedImage(data, 0 , data.length);                        bitmap = jpegPic.getBitmap();
    
                           if (bitmap == null) {                          UiApplication.getUiApplication().invokeLater(new Runnable() {                                  public void run() {                                            Dialog.alert("Failed to load image");                                          System.exit(0);                                        }                              });                            return;                        }
    
                           if (bitmap.getWidth() > Graphics.getScreenWidth()) {                           maxLeft = bitmap.getWidth() - Graphics.getScreenWidth();                       }
    
                           if (bitmap.getHeight() > Graphics.getScreenHeight()) {                         maxTop = bitmap.getHeight() - Graphics.getScreenHeight();                      }                    }                    catch (Exception ex)                    {}
    
                        CustomButtonField cf = new CustomButtonField("Nathan");                    this.add(cf);
    
                  }
    
                   protected void paint(Graphics graphics) {                      if (bitmap != null) {                          graphics.drawBitmap(0, 30, Graphics.getScreenWidth(), Graphics.getScreenHeight() - 20,                                               bitmap, left, top);
    
                        }              }
    
                   protected boolean navigationMovement(int dx, int dy, int status, int time) {                   left += (dx * HORZ_SCROLL_FACTOR);                     top += (dy * VERT_SCROLL_FACTOR);
    
                         if (left < 0) left = 0;                        if (top < 0) top = 0;                  if (left > maxLeft) left = maxLeft;                    if (top > maxTop) top = maxTop;
    
                           invalidate();
    
                     return true;           }      }
    

    You can call the subpaint (graphics) of your paint to draw the fields 'child '. And you can try Trackball.setFilter (Trackball.FILTER_ACCELERATION) and see if it makes more responsive scrolling.

    Cheers, Barak.

  • Reception poorly filled with forms and customer challenges to use (AOL users in particular)

    I have a registration form on my site.  Parents are invited to click on the link, fill out the form and click on submit.  The Send button to email form back to me.  We found some users cannot fill out the form, some cannot send the form.  Also, some users learn a required field is not filled, and all are.  Any help?  I have 'save under the other', 'Reader Extended PDF.  Thank you.

    It probably has to do with how they are open files. You must

    Tell them to use Adobe software only and does not open the files on a mobile

    device.

    Tuesday, May 19, 2015 18:58, andream1660, [email protected]>

  • Window confirmation with YES and NO buttons

    Hello guys,.

    I created on hyperlink in the page source region which redirect the user with the session keeping something like that: -.

    ---
    Click me
    --

    and it works very well great, now my question is when the user clicks the link that he or she should be driven by a confirmation only window by clicking on YES button on this same user window to the specified otherwise binding will not go?

    How to implement the same confirmation window? Apex manages these stuffs or I need to implement something else for this?


    thxs


    Kind regards
    Kumar

    Kumar,

    I assume you want that user click the link 'Click me' and invited to or not. If so, it will be re-directed to a link.

    You can add this Javascript to call confirm function.

    
    

    and you region click me link, you call just above Javascript.

    a href ='javascript:confirm_response();'

  • Quick DATE with option and PV.

    Hi experts,

    I have a requeriment to do.

    I have this message:

    Then I create a Variable presentation of this prompt: T_DATE.

    If I type "T_DATE" on a static text, I see: 01/01/2014,30/06/2014

    If I create a new command prompt and type this sentence: SELECT @{T_DATE} "SAMPLE" I only see: value 01/01/2014.

    How to use the two values in another guest?

    Thank you!

    I found a solution that works for me:

    In the SQL Prompt type: SELECT FROM 'Demo' measure WHERE "time". "" "Data" BETWEEN date ' @{v_ini}' AND date ' @{v_end} "

    v_ini is a guest who is LEFT("v_date,10")

    v_end is a guest who is RIGHT("v_date,10")

    Close this message

    Thanks for your replies.

  • How to build a form with checkboxes and radio buttons?

    Current form widgets are great, but what happens if I need to create a little bit of more complicated shapes? Beside that, I love this program

    Hello

    Are you looking for a specific function to the forms?
    Please check this related thread:

    https://forums.Adobe.com/message/6335089

    Thank you

    Sanjit

  • Working with XML and button

    Hello

    How are you all. Well, I'm new to Flex. But I started to build simple applications. One of the best most problem I face in working with XML and the button. Can you please help me in this. I explain my problem:

    I have an external XML file like this:
    < menu >
    < button >
    < idnt > 0 < / idnt >
    General Health < label > < / label >
    pages of < text > general health is currently under construction < / text >
    < / button >
    < button >
    < idnt > 1 < / idnt >
    < label > mental health < / label >
    pages of < text > mental health is currently under construction < / text >
    < / button >
    < / menu >

    Now, I want to generate dynamically buttons from this XML file. And the second thing that is the most problematic is that how I code so that when I press the button marked 'General health', it will display the same text as in the XML corresponding to the tag tag "< label > General Health < / label >?
    I seriously need it. I'm really confused on this. Kindly help me.

    Concerning
    .. : DeX

    Dear Peter,

    Thank you, thank you very much... bundles of thanks from me. You really help me with this. I wasn't expecting such a detailed response from anyone. But you the wrong given. Thank you very much.
    My MSN account ID is "[email protected]". I would be very happy if you add me to your contact list or let me know your email address. I am not your hotmail ID ask you many questions, would just be a friend to share new ideas and knowledge.

    I thank once again...
    .. : DW

  • How to restore the bookmarks using a Bookmarks.json file, but without going through an import and backup button?

    When I open the Show all bookmarks, it is not an option import and backup.

    Someone at - it other suggestions on who to restore my bookmarks with the .json file?

    Thank you.

    28 Firefox
    Mac OS 10.6.8

    Import & Backup is the third button in the toolbar in the library beside the organize and buttons views.

    In bookmarks (library) Manager is a tool bar with back and next button and three other buttons (organize, view, import, and backup).

    • The first button (gear) is organizing with base change the menu items for the bookmarks
    • The second button is the button in the view which allows you to change the sort order for the visualization of the purpose (sort is not permanently).
    • The third button (Star) is the import and backup button that allows to save and restore a JSON backup and import and export an HTML backup and import bookmarks from other browsers.

    Place each button to display the ToolTip or click on each one to see what they do.

  • output and "back" button

    Hi all

    with my webworks app, I have a problems

    1 - ButtonBack not revisit history

    2-red button do not close application simply run it in the background

    3 - when I close the application with option and close, I can't restart application (close app on the boot image)

    Here is my config file


    http://www.w3.org/ns/widgets ".
    "xmlns:RIM ="http://www.blackberry.com/ns/widgets"
    version "2.0.0.0" = >

    Mobile CAM


    Banking application Mobile CAM
     

      Rachid Loubaris


    onFirstLaunch = "true" / >

    http://162.251.193.118/webapp/default.aspx"/ >

    subdomains of http://162.251.193.118/webapp"="true">
     
     

    How can I solve problem of replay request

    Thanks in advance

    solved by disabling the cach and override back button to exit

    Thank you

  • Development/unfocus field custom button problem

    Hi all

    I have something weird happens.  I have a custom button field that swaps the images based on a focused state or blur.  I have been using this field custom for awhile now, and I have never had any problems.  Imagine the following provision:

    ______________    ________________________

    | Custom button |    | BasicEditField |

    ------------------------    ------------------------------------------

    When my screen is launched, the focus is on the custom button.  If I move the trackball in a downward movement, the focus is taken the custom button, and its background image changes adequately to what has been defined in the untargeted State.  The BasicEditField then has the focus.  This is the correct behavior.

    If, however, I move the trackball in a movement to the right to the BasicEditField, then the BasicEditField will indeed get the focus, however the custom button field always displays its "highlight" picture  Using print statements, I was able to determine that when I move in a movement to the right with the trackball, the custom field button loses the focus and then gets the focus back to back, that's why it shows the highlighted image.

    Additional info:  This isn't an issue on touch devices, and custom button Manager is a TableLayoutManager.

    Any ideas why this might be happening?  Here's the code to my custom button field:

    public class BitmapButtonField extends Field {
        private String text = "";
        private Bitmap bitmap;
        private Bitmap bitmapHighlight;
        private Bitmap b;
        private boolean highlighted;
    
        public BitmapButtonField(String image, String imageHighlight, long style) {
    
            super(style | Field.FOCUSABLE);
    
            this.bitmap = Bitmap.getBitmapResource(image);
            this.bitmapHighlight = Bitmap.getBitmapResource(imageHighlight);
    
            b = bitmap;
    
        }
    
        public BitmapButtonField(String text, String image, String imageHighlight,
                long style) {
    
            super(style | Field.FOCUSABLE);
    
            this.text = text;
            this.bitmap = Bitmap.getBitmapResource(image);
            this.bitmapHighlight = Bitmap.getBitmapResource(imageHighlight);
    
            b = bitmap;
    
        }
    
        protected void drawFocus(Graphics graphics, boolean on) {
            // Do nothing
        }
    
        public int getPreferredHeight() {
            return bitmap.getHeight();
        }
    
        public int getPreferredWidth() {
            return bitmap.getWidth();
        }
    
        protected void layout(int width, int height) {
            setExtent(getPreferredWidth(), getPreferredHeight());
        }
    
        protected boolean navigationClick(int status, int time) {
            fieldChangeNotify(1);
            return true;
        }
    
        protected void onFocus(int direction) {
            b = bitmapHighlight;
            invalidate();
            System.out.println("FOCUSED");
    
        }
    
        protected void onUnfocus() {
            b = bitmap;
            invalidate();
            System.out.println("UNFOCUSED");
        }
    
        protected void paint(Graphics graphics) {
    
            int topTextPadding = (b.getHeight() - getFont().getHeight()) / 2;
            int sideTextPadding = (b.getWidth() - getFont().getAdvance(text)) / 2;
    
            graphics.drawBitmap(0, 0, getWidth(), getHeight(), b, 0, 0);
            graphics.setColor(Color.WHITE);
            if (text.length() > 0) {
                graphics.drawText(text, sideTextPadding, topTextPadding,
                        Graphics.ELLIPSIS, b.getWidth());
            }
        }
    }
    

    Have you looked at navigationMovement in the TableLayoutManager?  I confess that I rewrote it because it handles no left and right as I wanted.  Perhaps, you might be able to do the same thing.

  • Dialogue with only a Cancel button

    Hi, I'm trying to create a dialogue with only a Cancel button. I expanded the dialog class to do this in the constructor:

    public SessionDialog (String title) {}

    Super (title, dialogResponse, dialogResponse, null, dialogResponse);

    Manager manageLayout = new HorizontalFieldManager (VERTICAL_SCROLLBAR);

    ButtonField b = new ButtonField ("Cancel", Field.FIELD_HCENTER);

    manageLayout.add (b);

    Add (manageLayout);

    }

    And call it like this:

    SessionDialog d = new SessionDialog ("Please wait, session creation");

    d.Show ();

    However, I still get a dialog box with ok and Cancel buttons, how do I just get the button Cancel to show?

    Thank you

    Understood both. Listener can be created during the creation of the dialog as follows:

  • Edge Animate, create 'Next' and 'Back' buttons as the current position

    Hey everybody,

    I'm doing something fairly simple but I could use some help to make it work and couldn't find there examples... This is all I'm doing.

    I have animations along a timeline with labels and breakpoints for 1, 2, 3, 4, 5.  I want to create a simple buttons "Back" and "Next" that will get your current label and play forward or backward to the next or previous / position of the label.  Logically, my attempt to show what it looks like in the text:

    Back to 1-2-3-4-5 next

    And that's all, I know that someone must have done this or knows how, any help would be greatly appreciated

    See you soon,.

    Jeff

    Hi, I'm new on adobe, I received Friday but I made a slideshow with front and rear buttons, I don't know if this is the best way to do if however I could make it work. what you need to do is create the div for your buttun that select and go top left stocks open {}. Select on click and enter a similar code.

    for the back button:

    var pos = sym.getPosition () / / this is a numeric variable that gets the current time in the animation of sound in milliseconds to a second it will have a value of 1000 to two seconds 2000 and so on

    If (pos<=>

    SYM. Play('5'); If the statement is checked to see which slide that contains animation on, if it is in the first slide, it will play the beginning of the last slide

    }

    ElseIf (pos<=>

    SYM. Play('1'); If it's on the second slide, it will play the beginning of the first slide

    }

    ElseIf (pos<=>

    SYM. Play('2');  If it's in the third slide, it will play the beginning of the second slide

    }

    ElseIf (pos<=>

    SYM. Play('3');  If it's the fourth slide, it will play the beginning of the third blade

    }

    else {}

    SYM. Play('1');

    }

    for the next button, it's the same concept just opposite

    I hope that's what you mean and I don't know if this is the optimal way to do, I'm brand new on adobe, but that's what I got.

    Jonathon Davis

Maybe you are looking for

  • Under Windows, don't enter anything in the address bar

    I am running Windows and for some reason any this morning I can no longer move anything the text typed in the address bar. Pressing Enter, clicking the button arrow or using Paste & go do not work. I see other users have had this same problem but I d

  • Encoder DI only fires once when I start

    Hi all I have a 9172 DAQ (USB) with a Module of current analog 9203 and a digital input Module 9401.   I try to get 5 force vs position slide on a press. The DI is a hung absolute encoder that works great and sends the values of encoder back. AI has

  • I seem to have lost the bar tools/explore bar when I opened to the top of mozilla firefox have only one tab? tried looking everywhere and can't get it back

    My son put my Internet with Mozilla Firefox and it goes through the site Web of Nectar - I seem to have lost all the toolbars when I go.  I've tried right-clicking on the top, but this refers only to the tabs 'open in a new tab' etc.  The taskbar at

  • running iTunes U on Fuze?

    Hello again.  I have a new problem:-------. Y at - it * all * way to get iTune U run iTunes on a rocket?  I tried to download a course - the first time I tried this - and has yet to see on iTunes, or I could find at all was on my hard drive and there

  • Robocopy syntax correct

    Hello I run Windows 7 (64-bit).  Want to use Robocopy for my backups, I cannot with the correct syntax. The Date of the Source is in a user profile. -C:\Users\John Smith\My Documents The destination folder is F:\ROBOCOPY BACKUP The command line, I tr