Help with JOptionPane - custom InputDialog

I need a little help here because I am trying to build a custom JOptionPane that prompts the user to choose 3 values from 3 drop-down lists and then returns those three values in a string. Specifically, this dialog is a very simple date chooser (because I don't really want to use JDateChooser right now). How do I overwrite the showInputDialog() method or the paintComponent() method to make it display three drop-downs?

Here's an example with multiple text fields. You should be able to modify it easily to use combo boxes:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class OptionPaneMultiple extends JFrame
     public OptionPaneMultiple()
          JTextField firstName = new JTextField(5);
          JTextField lastName = new JTextField(5);
          Object[] msg = {"First Name:", firstName, "Last Name:", lastName};
          Object[] options = {"Ok", "Cancel", "Whatever"};
          JOptionPane op = new JOptionPane(
               msg,
               JOptionPane.PLAIN_MESSAGE,
               JOptionPane.OK_CANCEL_OPTION,
               null,
               options);
          JDialog dialog = op.createDialog(this, "Enter Name...");
          dialog.show();
          int result = JOptionPane.OK_OPTION;
          try {result = ((Integer)op.getValue()).intValue();}
          catch(Exception uninitializedValue){}
          if(result == JOptionPane.OK_OPTION)
               System.out.println(firstName.getText() + " : " + lastName.getText());
          else
               System.out.println("Canceled");
     public static void main(String[] args)
          JFrame frame = new OptionPaneMultiple();
          frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
          frame.pack();
          frame.setVisible(true);
}

Similar Messages

  • Need help with a customized interactive web application for  apparel

    Help!!!!
    Hi I am a web designer at beginners stage with web
    devlopment. I am seeking guidance on how to develop a customized
    interactive web application so that the end user can change color
    and patterns of apparel on vector images such as teamsports
    uniforms and tshirts. Once the design is customized to their liking
    they can save it with all of the spec information in a file to
    there desktop or to a database to send to the manufacturer.
    Also looking for a possible way to use a CMS so I can upload
    templates of the garment easily for the end user to customize
    online. Can this be done and if so how? This is an example the kind
    of application I am looking for:
    http://www.dynamicteamsports.com/elite/placeorder.jsp
    I am in desperate need of some brilliant developer to help
    with this.
    Thanks in advance for anyone who is willing to assist or give
    me guidance,
    Danka
    "Reap what you sew"

    some parts of that are doable using non-advanced skills, but
    will be difficult and unwieldly if there are more than a few
    colors/patterns.
    saving the image to the server is a bit more advanced and
    you're going to need some server-side scripting like php, perl, asp
    etc. in addition to some flash programming ability.

  • Frustrated and seeking help with a custom sort order...

    I created a family photo album and arranged all of the pictures in a specific order and sync'd them with my iPad, unfortunately the pictures do not stay in the custom sequence.
    I tried Batch renaming with a Custom Name and Index, but the renaming is applied to the pictures based on the date they were created and not by the way I have arranged them.
    Is there a solution to my problem?
    TIA

    I flagged fifty photos and from that selection I created an album. I went to the album and dragged the photos in to the order I wanted them to appear after selecting Manual. Each time I now choose the manual option it arranges the photos into the sequence I created.
    The problem I'm having is that when I synchronize my iPad with iTunes the photos revert back to their original sort order, which is the default date they were brought in to Aperture.
    As I said, I tried to give them new names and index numbers using a batch command AFTER I arranged them manually, which works, however the names are assigned to the photos sequentially starting with oldest photos and not to photos as I have arranged them.
    Honestly, it would be easier for me to create a slideshow using the timeline in FCP, but a video is not what I'm after.
    I hope I have answered your questions.
    TIA

  • Please help with a custom javascript

    Hello,
    I am a military instructor, and I am trying to create a grade report card with Acrobat X Pro.  So far I have made good progress with the help of the forum community (just searching through the pages and pages of posts), but I am stuck on this issue.
    Like I stated,  I am creating a report card (of sorts) where our other instructor staff can input student test grades into the fields as they [students] progress through training.  The form is showing the particular test with an input field for the grade.  Lastly, the student's overal GPA is displayed in percent format.
    My conundrum: I am trying to code a field that all a user [instructor] will have to input is a numerical value with or without a decmil, and the field will display it as a percentage. 
    If I use acrobats default percentage, the number entered into the field will be multiplied by 100 (i.e. I enter 90 and acrobat displays 9000% in the field).
    I would just like to be able to type in 90, and 90% be displayed; or type in 88.5, and 88.5% be displayed.
    With the scripts I have entered, no decmils can be displayed, and the overal score is multiplying the average by 100, thus if I entered the number 90 in the first exam, the average calculates to 9000%.
    I am assuming the custom format script and custom keystroke script made the average calculation script not work correctly.
    Thanks in advance.  Ryan
    I have entered the following javascripts:
    1.  Document Level Script
    // Document-level function
    function DigOnlyKS() {
        // Get all that is currently in the field
        var val = AFMergeChange(event);
        // Reject entry if anything but digits
        event.rc = AFExactMatch(/\d*/, val);
    2.  Custom Format Script
    // Custom Format script for text field
    if (event.value) event.value += "%";
    3.  Custom Keystroke Script
    // Custom Keystroke script
    DigOnlyKS();
    4.  Custom Calculation Script for an Overal Grade Average
    event.value = myAverageFunction(["pk1","pk2","pk3","pk4","pk5","pk6","pk7","pk8","pk9","pk10","pk11","p k12","pk13","pk14","pk15","pk16","pk17","pk18","pk19","pk20","pk21","pk22","pk23","pk24"," pk25"]);
    function myAverageFunction(aNames) {
        // n = number of fields that have a numerical value
        // sum = some of values for the named fields
        var n = 0;
        var sum = 0;
        var v;
        // loop through array of name strings
        for (i = 0; i < aNames.length; i++) {
          v = this.getField(aNames[i]).valueAsString;
          // check for not a null string and not a space  and not is Not a Number
          if (v != "" & v != " " & isNaN(v) == false) {
             n++; // increment count
             sum += Number(v); // add to sum
        return (n != 0) ? (sum / n): "";

    Try,
    I'm sorry for being so ignorant with javascript.
    I placed that code in the custom keystroke like you suggested, but it did not work.    Is there a specific way I need to input that code in the custom keystroke area?
    I then tried to put it in the document level code and replaced (/\d*/, val) with your code... that really screwed thing up.
    So now I am stuck where I was before.
    I will try and show you what I am trying to accomplish:
    Right now, this is what is happening
    Exam 1
    Exam 2
    Exam 3
    Final Average
    95.5%
    95.3%
    94.3%
    95.033333%
    What I would like to do is to limit each field to 2 decmil places.
    Each "exam field" has the following:
    The "final average" field has the following:
    and this is in the custom calculations area of the "final average" field:
    Finally, I have this in the Documet JavaScripts area:
    I have a feeling this is an easy fix, but I just cannot figure it out.
    Thanks,
    Ryan

  • Can anyone help with a custom trigger?

    Hi - I know this is a tough one and appreciate anyone's help!
    I'm trying to create a custom trigger that confirms 2 fields belong to the same record. If they do, proceed with insert transaction.
    I have gone through the tutorial (from the old Interakt Discussion Board tutorial at http://www.interaktonline.com/Documentation/MXKollection/075000_tutorialdiscussionboard.h tm) on how to create a custom trigger that checks to see whether a duplicate message and subject exist in the table and if so, stop the insert. I have this working fine, using my own table and fields.
    Can anyone help me to change the script here to confirm that both fields belong to the same record? Here is what I have right now:
    $query = "SELECT * FROM dan_camptrans_login_familyid_confirmid WHERE family_id = ".KT_escapeForSql($tNG->getColumnValue("family_id"),$tNG->getColumnType("family_id"))." AND confirm_id = ".KT_escapeForSql($tNG->getColumnValue("familyconfirm_id"),$tNG->getColumnType("familycon firm_id"));
    $result = $tNG->connection->Execute($query);
    if(!$result) {
    $error = new tNG_error("Could not access database!",array(),array());
    return $error;
    } else {
    if($numberOfRecords = $result->recordCount()) {
    $uniqueFailed = new tNG_error("There is already a message with the same subject and content!",array(),array());
    return $uniqueFailed;
    } else {
    return NULL;
    Any help would be SUPER appreciated!
    Dan

    Thank you very much Shane for responding.
    Right now, if I fill out the form and enter any numbers in the family_id and familyconfirm_id fields that are currently NOT in the dan_camptrans_login_familyid_confirmid table, the form submits fine. If however, both fields already exist within the same record, the error is returned.
    I guess what I am looking for is the opposite. When the form is submitted, the table dan_camptrans_login_familyid_confirmid is checked. If both field entries are not within the same record, return the error.
    Basically, I am sending out a user ID and confirmation number via mail to users. When they register they need to enter in both of these numbers and only if they match the records will the registration proceed.
    The main recordset/form that this custom trigger is attached to is one for my user registration table. This custom trigger and associated table is only to confirm the user registering has the correct information to register.
    Thanks again - I hope that I am explaining this clearly.
    Dan

  • Need help with crazy custom calculations code in Acrobat XI pro

    Im trying to calculate some text feilds together and just cant figure it out.  I have two text feild boxes that I would input certain numbers to calculate in, Textfeild D5 and D6,  once the user supplies the numbers in the D5 and D6   I need a text feild (D9) to calculate and produce a number thats used in another calculation. Any help would be greatly appriciated. Im good at HTML and CSS but only begining with javascript. Im using acrobat XI pro and I put this code in the custom javascript area within the text feld "D9" properties.
    var Dsix = +getField("D6").value;
    var Dfive = +getFeild("D5").value;
    var B2 = 0.37;
    var B3 = 0.45;
    var B4 = 0.53;
    if (Dsix = 15){
    D9.value = B2*Dfive;
    if (Dsix = 30){
    D9.value = B3*Dfive;
    if (Dsix = 45){
    D9.value = B4*Dfive;

    Well thats makes since but unfortunitly it didnt work. The green text feild D9 is where im placing code at. they will be hiiden feilds. the red outlined text feilds are all input feilds. seconds is D6 and nozzels is D5.

  • Help with JOptionPane.showInputDialog

    Hi!!
    People here helped me before so trying my luck again:)
    In order to get information from people I use JOptionPane.showInputdialog,
    problem is if I need to get 2 different types of info I have to use
            naam = JOptionPane.showInputDialog(null, "Geef speler naam:");
            land = JOptionPane.showInputDialog(null, "Geef Land Speler:");Is there anyway to make this happen in 1 screen?
    Or do I have to make a new frame for that with textfields and such?
    if so, anyone got an example?

    im new here:) so.. New to Java Technology suits me
    well I guess.No it doesn't. New to Java forum is for classpath questions, simple compile time problems and lazy students to cross post their assigments into.
    Swing questions, such as the one you asked, should be asked in the Swing forum because the people who answer questions in there are more knowledgeable about Swing. Plus you will almost 100% likely to find working example codes from previous posts in the Swing forum for Swing related questions.
    Much more likely than in here anyway.

  • Help with saving custom stamps to SOAP repository.

    In my attempt to create a custom SOAP based comment repository i've found that i can save and retrieve all lightweight annotations perfectly except for any custom stamps that I've created (default stamps work great).  When i retreive the annotations from a different computer, it just displays a black box with a black x in the middle instead of actually displaying the stamp image.  My guess here is that I need to read the custom stamp image to a stream and then save it to the server along with the annotation data.  The problem is that I can't seem to get acrobat JS to detect and get the image (this.icon.length only counts default stamps).  I do have an AP property for the stamp which is the named appearance according to the documentation.  I just need some help now as to how i can retreive the stamp image data from the named appearance.
    Any help would be greatly appreciated.
    Thanks!

    Can anyone help me out with this?  I have a requirement to enable saving custom stamps to a central server but i can't seem to be able to retrieve the image data for storage.  Any leads would be greatly appreciated.
    Thanks!

  • Help with JOptionPane -- Popup Dialog Boxes

    I need to create a popup dialog box that looks like this:
    http://img88.imageshack.us/img88/6900/jbuttonpm2.jpg
    red = JTextField (Where the user will input a number that I need to store)
    green = Drop Down List with 1,2,3 as choices
    blue = JButtons for OK and Cancel
    So yeah, I need an easy way to collect a bunch of information from the user, and this was the best way I could think to do it. The user has to enter a number for all of the fields, but is there any way for the field to have a value of 0 there by default?
    I read some of the Java tutorials for using the JOptionPane's showXXXDialog but I wasn't sure if that can't of method could create such a complex dialog box. Any help would be really appreciated. How can I make that dialog box and get all the input I need from it?

    Create a panel containing red and green and pass it as message to JoptionPane.showConfirmDialog with OK_CANCEL_OPTIONS to have blue. If it returns OK_OPTION read and use values from panel. That's it.

  • Help with my custom event

    Hi all!
    I've extended JTextField to add some custom features. They can add my custom event called ValueChangedListener which listens for change in my textfields. Theese changes is registered in my JFrame holding the textfields so I can determine whether or not to save data to file on exit.
    My question is this:
    Can I listen to my custom events in a global way in my JFrame? Instead of adding the listener to each and every custom textfield (JFlexTextField) I would like to add ONE listener in my JFrame by calling MyJFrame.addValueChangedListener(ValueChangedEvent vce). (The method addValueChangedListener is located in my custom textfields).
    Thanks in advance.

    You need some kind of glue between the object that creates the message and the listeners. When the events are generated by your textfields, then those textfields needs at least one "address" to send the events to. Obviously, if the listener list is stored in the JFrame, your textfields will have difficulties using it.
    What you can do, which might help if you want to add several listeners to all the textfields, is:
    - Add only the JFrame as a listener to the textfields
    - Other listeners registers themselves with the JFrame
    - The JFrame keeps track of all the other listeners,
    - The 'valueChanged' method in the JFrame you forward the event to all the other listeners.
    You still have to call addValueChangedListener once for every textfield, though.
    You can also send a reference to the JFrame to the constructor for the textfields, and do the addValueChangedListener call in that constructor.

  • Need some help with JOptionPane

    Hi everyone. I want to create an OptionDialog with 3 textfields. So we have...
    String message1 = "The first Field";
    JTextField tf1 = new JTextField();
    String message2 = "The second Field";
    JTextField tf2 = new JTextField();
    String message3 = "The third Field";
    JTextField tf3 = new JTextField();
    Object o[] = {message 1, tf1, message2, tf2, message3, tf3};
    int result = JOptionPane.showOptionDialog(this, o, "A dialog", JOptionPane.OK_CANCEL_DIALOG,JOptionPane.QUESTION_MESSAGE, null, null, null);
    if(result == JOptionPane.OK_OPTION){
    Various actions here
    }However I want my dialog to focus in the first textfield, rather than, for example, in the OK button. I've tried a few alchemies but nothing actually worked. So I want your help :-). Is it possible to have the text indicator (you know that blinking | ) in the textfield? Can I do the same with a combo box too? I mean, how can I tell the programm to have selected the first option of the combobox when the dialog pops up?
    Thanx in advance

    Issue fixed.
    try
                String m1 = "One Field";
                String m2 = "Two Fields";
                String m3 = "Three fields";
                JTextPane tf1 = new JTextPane();
                JTextPane tf2 = new JTextPane();
                JTextPane tf3 = new JTextPane();
                Object o[] = {m1, tf1, m2, tf2, m3, tf3};
                JOptionPane pane = new JOptionPane(o, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null, null, o[1]);
                JDialog dialog = pane.createDialog(this, "A new Dialog");
                dialog.setVisible(true);
                Object selectedValue = pane.getValue();
                if(((Integer)selectedValue).intValue() == JOptionPane.OK_OPTION)
                    <<VARIOUS ACTIONS HERE!>>
    catch(Exception e){ }Thnx everyone for stopping by!

  • Help with the custom tag

    Hi
    i want to make a custom tag encapsulating certain functionalities of existing tags in one tag namely tomahawk dataPanel and html facets.
    Where can I get the source for html jsf tags so that I can look into it and modify.
    Thanks

    Originally posted by: mbuc.edp-progetti.it
    Would you like to know a fine workaround?
    If you have in your jsps a reference to the tld like this:
    <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
    make a C:\WEB-INF\ directory on your PC and copy in there your tlds
    (C:\WEB-INF\struts-html.tld). The same for linux: /WEB-INF/struts-html.tld.
    So you do not have to change anything in web.xml nor in the jsp pages!
    Bye,
    Marco.
    "marco" <[email protected]> ha scritto nel messaggio
    news:cfhrgj$bcj$[email protected]..
    > Davis,
    > thanks for the reply. I followed your suggestion and now I am able to see
    > the code assist working.
    > I am currently using the lomboz editor, but one thing that is missing in
    > lomboz and is present in the structured editor (and in Intellij Idea) is
    the
    > ability to see where a tag is opened and closed, also for html tags.
    Perhaps
    > to someone this should seem not so important, but for me it is very
    usefull!
    >
    > As a first impression, I can only make a lot compliments to both
    > contributions (ObjectWeb and IBM).
    >
    > Bye,
    > Marco.
    >
    >
    > "David Williams" <[email protected]> ha scritto nel messaggio
    > news:[email protected]..
    > >
    > > No, you're not missing anything. Its just with that version of code the
    > > "tld resolver" (that knows where to look for TLD's) is not correct. I
    > > haven't tried it with struts, but with a minor test I tried,
    > > I just made a copy of the TLD to put in the same folder as the JSP file.
    > > Then the editor (and content asssit), can find it and all should be ok.
    Of
    > > course, I'm not suggesting this for a long term solution, but just to
    see
    > > if it allows you to get a little further in evaluating overall.
    >
    >

  • Help with datagrid custom item renderer

    Hi ,
    I have a datagrid in which I have a column with a checkbox and a custom Checkbox header renderer and an item renderer.
    When I try to disable the grid the checkbox column does not get disabled?
    Is there any way I can disable the entire grid along with the checkbox column?
    Thanks.

    Override updateDisplayList on the renderer and set the .enabled to match
    owner.enabled.

  • Help with JTreeTable custom cell renderer!

    Hi.
    I've followed diligently the complete TreeTable2 example found on the Sun site. http://java.sun.com/products/jfc/tsc/articles/treetable2/
    What I'm trying to do is to add alternate-row shading on the Column(0) of the JTreeTable where the Column class is "TreeTableModel".
    so, from the example, I've added the following setCellRenderer declaration to TreeTableExample2.java:
         protected JTreeTable createTreeTable() {
              JTreeTable       treeTable = new JTreeTable(model);
              treeTable.getColumnModel().getColumn(1).setCellRenderer
              (new IndicatorRenderer());
              treeTable.getColumnModel().getColumn(0).setCellRenderer
              (new MyTableCellRenderer());Then, I subclass DefaultTableCellRenderer as shown below, in a new class called "MyTableCellRenderer"
    import java.awt.Color;
    import java.awt.Component;
    import javax.swing.JTable;
    import javax.swing.table.DefaultTableCellRenderer;
    import javax.swing.table.TableCellRenderer;
    public class MyTableCellRenderer extends DefaultTableCellRenderer implements TableCellRenderer
         private static final long serialVersionUID = 1L;
         public MyTableCellRenderer() {
         public Component getTableCellRendererComponent(JTable jtable, Object obj, boolean isSelected, boolean hasFocus, int i, int j)
              if (i % 2 == 0 && !isSelected) {
                   this.setBackground(new Color(214,226,255));
                   this.setForeground(Color.BLACK);
              } else if (isSelected)
                   this.setBackground(new Color(204, 204, 255));
              else {
                   this.setBackground(Color.white);
              //if (obj != null)
              this.setValue(obj.toString());
              System.out.println("obj: " + obj.toString());
              System.out.println("obj type: " + obj.getClass().getName());
              return ((Component) (this));
    }I've been pulling out whatever few hairs I have left in my sparse scalp to get this working, but it's looking grim thus far.
    Here are links to screenshots of my progress, or lack thereof:
    Original Working TreeTable II
    http://www.pharmalytix.com/original_treetable.jpg
    My Not-working Tree Table II w/ Custom Cell Renderer
    http://www.pharmalytix.com/customtablecellrenderer_treetable.jpg
    thanks again - !!

    phew! finally got this sucker working. I had to retrieve the default rendererer of my TreeTable's TreeTableModel class column, which is the JTree and then, in its component-form, start mucking about with its stylings. The real black-hole of progress was caused by my brain imploding from not being able to understand that a "Component" was what represented the "thing" whose behaviour I wanted to alter, be it a Jtree node or Jtable cell.
              treeTable.getColumnModel().getColumn(0).setCellRenderer(new TableCellRenderer() {
                   public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int col) {
                        Component comp = treeTable.getDefaultRenderer(TreeTableModel.class).getTableCellRendererComponent(table, value, isSelected, hasFocus, row, col);
                        if (row % 2 == 0 && !isSelected) {
                             comp.setBackground(new Color(214,226,255));
                             comp.setForeground(Color.BLACK);
                        } else
                             if (isSelected)
                                  comp.setBackground(new Color(204, 204, 255));
                             else {
                                  comp.setBackground(Color.white);
                        return comp;
              });In all of its ravishing glory:
    http://www.pharmalytix.com/alternateshading_treetable.jpg
    Edited by: DataHog on Nov 6, 2007 10:21 AM

  • Help with searching custom metadata tags

    I have written a Photoshop JavaScript for my employer which allows my users to enter custom information into metadata fields. My intention was to use Bridge to create a searchable asset management system for these files. However, I am running into several problems in allowing my users to search for images with the criteria that they are looking for.
    My first thought was to create my own search dialog which then looks for files whose metadata matches the search criteria. I was able to do this and return an array of thumbnail objects, but to my surprise there does not appear to be a way to create a new window which shows these thumbnails? (without creating a new folder object and copying the files there which would tie up too many resources.)
    My next thought was to create a custom namespace/panel for my metadata. This also works up to a point. I cannot seem to get my custom metadata fields to show up in Bridge's search or filter areas. I see the SDK example for creating search conditions for a custom node, but how can I modify search conditions for "normal" nodes (folders)?
    I'm sure that many of you have run into these issues, there are several posts in this forum and others from people with similar questions. I'm not seeing much in the way of answers, however. Any information would be much appreciated.

    I am no expert, in fact a total beginer with Bridge scripting.
    I have also found that it a problem displaying the required thumbnails. To get around this problem I have used the label rating, changing all the thumnails I don't wont to reject.
    IE:
    var items = app.document.visibleThumbnails;
    for (var i = 0; i < items.length; i++){
    var md = items[i].synchronousMetadata;
    md.namespace = "http://ns.adobe.com/photoshop/1.0/";
    if (md.Keywords != "") items[i].rating=-1;
    This will only show thumnails that do not have keywords so long as the view "Show Reject Files" is not ticked.
    I suppose if you used the rating you could copy them into a field that you could restore from.
    As for the sorting I haven't done much with that except this sort of code should work on custom metadata.
    new SortCriterion("MyDateSort", "date", "http://ns.adobe.com/xap/1.0/", "CreateDate");
    var mySortObj = {};
    mySortObj.name = "MyDateSort";
    mySortObj.reverse = false;
    var mySortsArray = [];
    mySortsArray.push(mySortObj);
    app.document.sorts = mySortsArray;

Maybe you are looking for