Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Java program to display 2D Array in ComboBox

  1. #1
    Junior Member
    Join Date
    May 2008
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Java program to display 2D Array in ComboBox

    How do I select a column in the array? I can select the row just fine but for my ComboBox I need to select the column as the values for the combobox.

    Thanks in advance.

    String[][] partNumberString =
    	{
    	{"PR214",	"MR43T", 	"RBL8",	"14K22"},			
    	{"PR223",	"R43",		"RJ6 ",	"14K24"},
    	{"PR224",	"R43N ",	"RN4 ",	"14K30"},
    	{"PR246",	"R46N",		"RN8 ",	"14K32"}};
     
    	//All the GUI objects
    	JPanel mainPanel = new JPanel();
    	JComboBox plainWrapComboBox = new JComboBox(partNumberString[[B]??[/B]]);


  2. #2
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 286 Times in 225 Posts
    Blog Entries
    4

    Default Re: 2D Array and ComboBox

    I'm not sure if you can do that

    How about just doing this:

    String[][] partNumberString =
     {
     {"PR214", "PR223", "PR224", "PR246"},   
     {"MR43T", "R43", "R43N", "R46N"},
     {"RBL8", "RJ6", "RN4", "RN8"},
     {"14K22", "14K24", "14K30", "14K32"}
     };

    Then you can select the row and get the same result your after.
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

    Looking for a Java job? Visit - Java Programming Careers