Drop down menu or combo box in jtable

Hi there I nee urgent help I have a jtable and I am collecting information to populate the table dynamically, the problem is I some of the strings that populate certain cells is longer the the width of the cell in a particular column, I thought I could use a combo box and split the strings up so I could have some type of drop down menu showing the information, but when I populate the combo box and instantiate the defaultcell renderer with the combobox it sets all cells in that column with the same information I would like to have it displaying the actual information for every row within that column
or if you can give me any ideas as to how I can avoid this happening or maybe an alternative method of showing these long strings in the table some kind of drop down.
Kind Regards Michael

the problem is I some of the strings that populate certain cells is longer the the width of the cell in a particular column,Set a tooltip to display the entire text of the cell. Here is a simple example;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class TableToolTip extends JFrame
     public TableToolTip()
          Object[][] data = { {"1234567890qwertyuiop", "A"}, {"2", "B"}, {"3", "C"} };
          String[] columnNames = {"Number","Letter"};
          JTable table = new JTable(data, columnNames)
               public String getToolTipText( MouseEvent e )
                    int row = rowAtPoint( e.getPoint() );
                    int column = columnAtPoint( e.getPoint() );
                    Object value = getValueAt(row, column);
                    return value == null ? null : value.toString();
          JScrollPane scrollPane = new JScrollPane( table );
          getContentPane().add( scrollPane );
     public static void main(String[] args)
          TableToolTip frame = new TableToolTip();
          frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
          frame.setSize(150, 100);
          frame.setLocationRelativeTo( null );
          frame.setVisible(true);
}If you want to get fancier than you could set the tooltip text only when the width of the text is greater than the width of the column. Here is an example of this is done with a text field. You would need to modify the code to refer the to table for the text string and the TableColumn for the width.:
JTextField textField = new JTextField(15)
     public String getToolTipText(MouseEvent e)
          FontMetrics fm = getFontMetrics( getFont() );
          String text = getText();
          int textWidth = fm.stringWidth( text );
          return (textWidth > getSize().width ? text : null);
textField.setToolTipText(" ");
I thought I could use a combo box and split the strings up so I could have some type of drop down menu showing the informationIf you want to proceed with this approach then check out this posting:
http://forum.java.sun.com/thread.jspa?forumID=57&threadID=637581

Similar Messages

  • Photoshop Elements12 - crashing when using Adjustment Layers. When opening the drop down menu there are 'boxes' for Black

    Does anyone else have problems using the Channel Mixer?
    This problem only started after the opening screen started to 'advertise' the advantages of moving to Cloud

    Which operating system are you using?
    Can you post a screenshot of what your seeing with the menus?
    All adjustment layers cause pse 12 to crash or only certain ones?
    The channel mixer adjustment layer isn't included with pse 12, so did you download an action for the channel mixer adjustment layer?
    I never use the welcome screen since it seems to cause so many problems with the elements versions that have it, but rather make a shortcut to the editor and/or organizer and use those instead.

  • Add a Drop down menu / Combo Box into a specified cell of a multi column lsit box

    Hello,
    i have a question how to manipulate a cell of a multi column list box in that way that i can add a drop down menu or a combo box in this cell?
    Is this possible in LabView?
    Thank you!

    Wow, I took a look at the alternate code posted here at that really takes you through gyration (also a similiar comment I see on Lava) to perform what I've done with a few functions....
    See the Pics and attached VI for how its done. KISS, I added an event stucture and changed my first enum case to " " (i.e. a blank) to make it look like the other posted code....
    Attachments:
    DropDownMenuInABox.vi ‏18 KB
    DropDownMenuInABox_FP.PNG ‏18 KB
    DropDownMenuInABox_BD.PNG ‏36 KB

  • How to use drop down menu in JTables

    Hi, i'm trying to add an drop down menu to my jtable so that people can select a set number of texts from an enum type. How can this be accomplished?
    My current Code: /**
    * Bill Huang
    * Started: Nov 07, 2007
    * Dossier
    package packageSolo;
    import javax.swing.*;
    import java.awt.*;
    public class SpreadSheetGUI extends JPanel{
         private void debug(int x){
              //System.out.println(x);
         protected static Object[][] data;
         protected static int classroomAmount = 0;
         protected static JTable jtable;
         protected static String[] columnNames = { "Class Room Number", "Period One", "Period Two", "Period Three", "Period Four" };
         public SpreadSheetGUI(){
              super(new GridLayout(1,0));
              String input;
              int flag2 = 0;
              int flag4 = 0;
              int flag5 = 0;
              int flag8 = 0;
              input = JOptionPane
                        .showInputDialog("How many classrooms are there?");
               * see if the user wantes to quit at this point
              if (input == null) {
                   debug(4);
                   int exitint = 0;
                   exitint = JOptionPane.showConfirmDialog(null,
                             "Do you want to exit?", "Exit?",
                             JOptionPane.OK_CANCEL_OPTION);
                   if (exitint == 0) {
                        try {
                             System.exit(1);
                        } catch (SecurityException eb) {
                             System.out.println("exit");
              while (flag4 == 0) {
                    * this while loop with flag2 is for checking if the thing is of int
                    * class
                   while (flag2 == 0) {
                         * try to get a integer, check for a bad input class
                        try {
                              * parse, and if success set flag2 to 1 and break out this
                              * while loop
                             classroomAmount = Integer.parseInt(input);
                             flag2 = 1;
                             debug(2);
                        } catch (NumberFormatException ec) {
                             debug(3);
                              * ops user input was not a integer class
                             JOptionPane
                                       .showMessageDialog(null,
                                                 "Enter a positive integer only",
                                                 "Number Format is Wrong",
                                                 JOptionPane.ERROR_MESSAGE);
                             input = JOptionPane
                                       .showInputDialog("How many months are there?");
                              * see if the user wantes to quit at this point
                             if (input == null) {
                                  debug(4);
                                  int exitint = 0;
                                  exitint = JOptionPane.showConfirmDialog(null,
                                            "Do you want to exit?", "Exit?",
                                            JOptionPane.OK_CANCEL_OPTION);
                                  if (exitint == 0) {
                                       try {
                                            System.exit(1);
                                       } catch (SecurityException eb) {
                                            System.out.println("exit");
                    * this while loop sees if the integer is smaller than 0 so the
                    * array cannot be a real one
                   while (flag5 == 0) {
                        // numamountint = Integer.parseInt(numamount);
                        if (classroomAmount < 0 || classroomAmount > 12) {
                             debug(5);
                             JOptionPane
                                       .showMessageDialog(null,
                                                 "Enter a positive integer that is smaller than 12",
                                                 "Number Format/Size is Wrong",
                                                 JOptionPane.ERROR_MESSAGE);
                             input = JOptionPane
                                       .showInputDialog("How many months are there?");
                             if (input == null) {
                                  int exitint = 0;
                                  exitint = JOptionPane.showConfirmDialog(null,
                                            "Do you want to exit?", "Exit?",
                                            JOptionPane.OK_CANCEL_OPTION);
                                  if (exitint == 0) {
                                       try {
                                            System.exit(1);
                                       } catch (SecurityException eb) {
                                            System.out.println("exit");
                              * this while loop check for number format again
                             while (flag8 == 0) {
                                  try {
                                       debug(6);
                                       classroomAmount = Integer.parseInt(input);
                                       flag8 = 1;
                                  } catch (NumberFormatException ec) {
                                       debug(7);
                                       JOptionPane.showMessageDialog(null,
                                                 "Enter a positive integer only",
                                                 "Number Format is Wrong",
                                                 JOptionPane.ERROR_MESSAGE);
                                       input = JOptionPane
                                                 .showInputDialog("How many months are there?");
                                       if (input == null) {
                                            int exitint = 0;
                                            exitint = JOptionPane.showConfirmDialog(null,
                                                      "Do you want to exit?", "Exit?",
                                                      JOptionPane.OK_CANCEL_OPTION);
                                            if (exitint == 0) {
                                                 try {
                                                      System.exit(1);
                                                 } catch (SecurityException eb) {
                                                      System.out.println("exit");
                        } else {
                              * here the input is greater than 0 so it sets flag5 and 4
                              * then break out of the while loops
                             debug(8);
                             flag5 = 1;
                             flag4 = 1;
              data = new String[classroomAmount][5];
              jtable = new JTable(data, columnNames);
              jtable.setPreferredScrollableViewportSize(new Dimension(800, 600));
              JScrollPane scrollPane = new JScrollPane(jtable);
              this.add(scrollPane);
              this.show();
    }

            Object[] possibilities = {"1", "2", "3"};
            input = (String) JOptionPane.showInputDialog(null,
                    "Please choose the number of classrooms:",
                    "How many classrooms are there?",
                    JOptionPane.PLAIN_MESSAGE,
                    null, possibilities, "1");Edited by: Andre_Uhres on Nov 8, 2007 8:22 AM
    I thought you need a combo for JTable row set. Seems I misunderstood.
    See next posting.

  • Multiple drop down menu items to populate the a separate text box...more help please

    Thanks to Gilad D67 for showing me how to have multiple drop down menu items appear in a separate text box. This stuff blows my mind. Is there any script I can use to make a new drop down menu item appear in the same text box, but on a new line below a previous entry. For example. I select 'cat' from my drop down menu and it appears in my text box. Now I choose 'dog' from my menu and it appears in my text box like so  'cat dog.' Is there any way I can make 'dog' go straight to a new line automatically without having to manually go into the text box and change it?
    cat
    dog (new selection goes straight to a new line)
    Now, I don't have a clue if this is also possible, but imagine, I don't like my drop down menu selection of 'dog' and I go back into the menu and I change to 'rat' but in the text box, 'dog' still appears and 'rat' is added. Do I have to manually delete 'dog' from the text box or is there script that can do this for me.
    Any assistance would be incredible. It amazes me how people know this stuff.
    This is the script I have so far
    (function () {
        // Do nothing if not committed
        if (event.willCommit) return;
        // Set up an array to hold the individual paragraphs of text
        var aQuotes = [3];
        // Populate the array with the paragraph text
        aQuotes[0] = "Use common singular nouns, plural nouns [plural ‘s’] and proper names to say what things are"
        aQuotes[1] = "Use numbers 1–10 to count"
        aQuotes[2] = "Use basic adjectives and colours to say what someone/something is or has"
        // Get the selected item, which is the export value of the selected combo box item
        var item = event.changeEx
        // Display the text corresponding to the selected item in the text field
        getField("Text30").value += " " + aQuotes[item];

    You have to set the option for the text field to be multiline and then change the last line of the script to:
    getField("Text30").value += "\r" + aQuotes[item];
    To reset the field you can use a separate button with a Clear Form command, and then you just select this one field from the list.

  • Multiple drop down menu items to populate the same separate text box. How can I do it?

    In Acrobat Pro X, I've figured out how to create a drop down menu with items that will populate a separate text box, but how can I get multiple menu items to populate the same text box. For example. My drop down menu has three items  cat, dog, mouse. I choose cat and it appears in my separate text box (hooray). Next, I choose 'dog' from the same menu. I would like it to appear in the same text box along with my previous selection 'cat.' Is this possible? I'm very new to Java Script, any assistance would be greatly appreciated! Thank you

    She is the script I'm using
    (function () {
        // Do nothing if not committed
        if (event.willCommit) return;
        // Set up an array to hold the individual paragraphs of text
        var aQuotes = [3];
        // Populate the array with the paragraph text
        aQuotes[0] = "cat"
        aQuotes[1] = "dog"
        aQuotes[2] = "mouse"
        // Get the selected item, which is the export value of the selected combo box item
        var item = event.changeEx
        // Display the text corresponding to the selected item in the text field
        getField("Text field 1").value = aQuotes[item];

  • Add value entered in a text box to drop down menu options

    hi everyone
    i am making a pdf form for medical imaging report. i have a text box where the users enters a number, i want this entered number to appear within a drop down menu options
    thanks

    Hi Alexander,
    I can explain you the details there is a list as you mentioned Newsletter with a column email in it you are right but for your answer ya i can use enforce unique values for that column but if i am using it it gives me an error in the next page what i want
    is just beside my text box to say that already registered user.I want that functionality that is what i meant.
    Thanks
    Eswar
    Eswar Chand Teki

  • A box with a blue outline appeared in my bookmark drop-down menu. I can't get rid of it, and it obstructs the view of the bookmarks as I scroll up or down. Help!

    I was trying to bookmark a page, using the "Choose" menu in the bookmarks. I must have touched a key by accident, and a box with a blue outline & the name of one of my folders appeared in my bookmark drop-down menu. At first the box contained the folder name, then I was trying to delete the box, and erase the name, thinking it might get rid of the box, but it didn't. I can't get rid of this box! It obstructs the view of what is underneath. It stays in the same position as I scroll up & down in the drop-down menu, and it hides what is underneath. Please help me get rid of this box. It is driving me crazy! Thanks!

    Start Firefox in <u>[[Safe Mode]]</u> to check if one of the extensions or if hardware acceleration is causing the problem (switch to the DEFAULT theme: Firefox/Tools > Add-ons > Appearance/Themes).
    *Don't make any changes on the Safe mode start window.
    *https://support.mozilla.org/kb/Safe+Mode
    *https://support.mozilla.org/kb/Troubleshooting+extensions+and+themes
    See also:
    *http://kb.mozillazine.org/Corrupt_localstore.rdf

  • Acrobat Forms - Make fillable text box appear after box checked or drop down menu item selected

    I have been asked to build an approvals form for my workplace however the approval processes vary considerably depending on the subject. I have been asked to create a list of topics in the form of check boxes or a drop down menu which will then populate a list of text boxes with differing approval authorities and corresponding spaces for signatures.  i.e. if 'Topic 1' is selected a list of names and signature spaces will appear, however if 'Topic 2' is selected a different list of names and signature spaces will appear instead.
    In order to achieve this I think I only need to find out how to link check boxes or drop down menu items to the appearance of different text boxes.
    I should also add that I am a beginner with this stuff.
    Thank you very much for any help you can provide.

    Remove the red coloured part
    ul.MenuBarHorizontal ul.MenuBarSubmenuVisible {
    left: auto;
    top:0;
    or start again with the original SpryMenuBarHorizontal.css and follow the rules as in http://www.dwcourse.com/dreamweaver/ten-commandments-spry-menubars.php#one.
    Either way will get you back on track.
    Good luck.
    Ben

  • Selection Box and some repeats in drop down menu problems, please help

    Hello,
    I'm not quite sure what i have managed to turn on but everytime i click anything on my mac it gets a black box around it... I have no idea how to turn it off... can someone help me?
    Also my restart, Log out and Shut down seem to be repeating themselves in my apple drop down menu... is the normal? I don't remember it before. I'm working on a Mac Pro using Mac OS X 10.4.7.
    Any help would be much appreciated.

    Ahh thank you so much!
    I don't know how I managed it but it was really annoying me and now its gone. Wonderful.
    Thank you again.

  • Drop down menu box query

    How do I stop the drop down menu box from always appearing when try to open anything?

    Use trackpad and mouse gestures
    http://docs.info.apple.com/article.html?path=Mac/10.7/en/mh35869.html

  • I can't get the drop down menu in the search box in newest version.

    I just updated to the latest version (35.0) and can't get drop down menu. I couldn't get it in the last version either. I've filled everything out in the change settings page but still can't figure out how to get my choices to show up. (Please keep answers simple--I'm not a computer geek but I can follow clear directions.)

    ''Kathy99 [[#question-1042648|said]]''
    <blockquote>
    I just updated to the latest version (35.0) and can't get drop down menu. I couldn't get it in the last version either. I've filled everything out in the change settings page but still can't figure out how to get my choices to show up. (Please keep answers simple--I'm not a computer geek but I can follow clear directions.)
    </blockquote>
    ''Kathy99 [[#question-1042648|said]]''
    I see it now. Thank you, Phillip. I read the help page before, but I think it would help if that page pointed out that the options you have selected will appear at the bottom of the list of suggestions after you type a search in the box. Also that would have been clearer if I did not select give suggestions. The key point for my understanding was that I had to type a search first in order to get the options to appear, which is the opposite of how it worked before. Definitely fix that help page to make that part clear. And thanks again, so much.

  • In Edit this Bookmark box there is no drop-down menu and there used to be!

    When we ask to "bookmark this page" we are presented with the appropriate box but there is no drop-down menu on demand just three options from the past followed by an empty box. We used to be presented with all our bookmark categories and then we did something which stopped this (cannot remember what) and we cannot recover the original presentation. Hope this is clear? Please forgive incorrect terms!

    Not really clear, but I will try to clear up some of what you see, and tell you that you can fix most of the problems by installing the "'''Add Bookmark to Here2'''" extension, which can help clear up some of the ambiguities, but not all of them, so read the explanation below.
    The main problems are:
    # You can't really do much unless/until you expand the dialog that is the first drop-down button that appears by itself at the far right as [V] or as [^]. With the extension you can make the expansion automatic for each time you open the bookmark dialog.
    # The drop-down to the left shows the most recently bookmarked to folders, but once you click on it you will be at the selected folder and can scroll through all of your bookmarks, expanding where necessary to see subfolders but not bookmarks.
    # Below that is a drop-down for tags, this is the most confusing thing every added to a dialog because it gets close to and confused with other drop-downs. My suggestion is if you don't use tags, eliminate the tag display entirely with the extension.
    Additional advantages of installing the extension.
    # Adds back the keyword field, which is essentially a single alias for a bookmark and will allow you to invoke a commonly used bookmark without the foolish additional searching and clicking to lookup or use a bookmark, and it allows you to include substitution values associated with a shortcut. (see [http://dmcritchie.mvps.org/firefox/kws.htm keyword shortcuts] for examples and how to make your own).
    #Allows you to make use of the Description field, you can modify it to suit yourself, but correctly made web pages have a description, and you can include that or modify how it reads for your bookmark. The description is not searchable when you try to search your bookmarks.
    #Like its name implies you select right-click a bookmark folder and use the "Add Bookmark Here" to bookmark into the folder. Feature further enhanced if you install the "Multiple Tab Handler" extension.
    #The text areas within the dialog are expandable by moving the bottom border of the areas, see the third picture shown on the add-ons page.
    References:
    * '''[https://addons.mozilla.org/firefox/addon/add-bookmark-here-2/ Add Bookmark Here ²]''' extension
    * -- my notes -- http://dmcritchie.mvps.org/firefox/firefox.htm#addbookmarkhere2
    * -- more notes -- http://dmcritchie.mvps.org/firefox/addbookmarkhere2.txt
    * [https://addons.mozilla.org/firefox/addon/multiple-tab-handler/ Multiple Tab Handler] extension
    * -- my notes - -http://dmcritchie.mvps.org/firefox/multiple_tab_handler.txt
    Additional references:
    * [https://support.mozilla.com/en-US/questions/836619 How do I save a page to my imported favorites? Double clicking the star does not allow me to scroll all of my folders to choose and neither does clicking on &quot;bookmarks"? | Firefox Support Forum | Firefox Help]
    * [http://webcache.googleusercontent.com/search?q=cache:http%3A%2F%2Fkb.mozillazine.org%2FBookmark_dialog Bookmark dialog - MozillaZine Knowledge Base] (cached copy) -- real link is [http://kb.mozillazine.org/Bookmark_dialog here].
    * [https://support.mozilla.com/questions/872310 Can one add an item to the bookmarks toolbar bookmarks menu? | Firefox Support Forum | Firefox Help]
    Additional disambiguation may be needed:
    :"bookmark categories" -- suggested last used bookmark folders, or bookmark folders, or tags -- I think I covered those above if not, indicate what you meant.

  • TS3276 the images (attachments) are automatically resized (smaller) when I send them to a customer. My email screen does not show a drop down menu box where you can leave as actual size. Is there a setting elsewhere that can be set.

    Any suggestions on problem I have. I receive images, say a file that is 3 mgs through email on Safari mail and when I try to resend it or forward it or any other larger file, when it sends the file is reduced by about 1/3. My screen does not show and drop down menu with a feature to keep actual size or reduce that is suggested when I looked up solutions to the problem.  I can't find a setting anywhere in mail that I can change to make sure my files are kept at actual size. I figure a setting got changed -don't know how - but it happened about a month ago. Caused problems as I work in graphics can't send files to clients as they come out too small. Any suggestions on how to fix.
    Thanks

    What email program are you using? And what do you mean by "Safari mail"?

  • File format drop down menu does not appear in the export dialogue box

    I am trying to export a book project as individual jpeg files and I can't see the drop down menu to choose what file format I want to export the file as. All I can do is export it as a .pdf which does not help me.

    What program are you using? This is the main Creative Cloud Application forum. This needs to be in the forum that matches the program you are using.
    Benjamin

Maybe you are looking for

  • IPhone 4 can't synch with itunes 11 (Error -50)

    Hi, I have the latest versions of OS Mavericks, iTunes and on my iPhone 4 but whenever I start iTunes there is a -50 Error that just appears and does nothing, and when I connect my iPhone it says "iPhone cant be synchronized. Unknown error (-50)". It

  • HP Officejet Pro 8600 Plus On-Glass Copy Problem

    When I try to copy on-glass, the scanner bar does not move to the far right edge so it cuts off about 3 inches of the top of the document being copied. Scanning from document feed and sending items to be printed work fine. This question was solved. V

  • Can i upgrade exchange 2007 to exchange 2013 on same small business server 2008 machine?

    Hi, I have small business server 2008 with exchange 2007 installed in my organization, Now I need to upgrade exchange 2007 to exchange 2013 on same small business server 2008 standard edition. I already tried to upgrade but not successful. can i upgr

  • ITunes looks like it's working, but won't play a thing - NOTHING

    I don't have the same issues as others on here. I updated to iTunes 7.0.2 a ways back but only today did I update my iPod Nano (1st gen.) to the updated firmware. I then had to restore my iPod Nano and it luckily reloaded all my music from my library

  • How can i download my voice call conversation

    Hello, Could someone please tell me, how can i download my voice call conversations. Its very importantn for me to get this download. Please reply me asap or could someone give me the skype customer support contact number so that i can talk to them a