Results 1 to 3 of 3
  1. #1
    crazydeo is offline Member
    Join Date
    May 2008
    Posts
    21
    Rep Power
    0

    Question [SOLVED] 2D Array

    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.

    Java Code:
    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();
    	JPanel addPanel = new JPanel();
    	JComboBox plainWrapComboBox = new JComboBox(partNumberString[[B]??[/B]]);
    Last edited by crazydeo; 05-27-2008 at 10:19 PM.

  2. #2
    M77's Avatar
    M77
    M77 is offline Member
    Join Date
    May 2008
    Location
    LV
    Posts
    43
    Rep Power
    0

    Default

    Quote Originally Posted by crazydeo View Post
    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.

    Java Code:
    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();
    	JPanel addPanel = new JPanel();
    	JComboBox plainWrapComboBox = new JComboBox(partNumberString[[B]??[/B]]);
    String[] column=new String[4];
    for (int y=0; y<4; y++) column[y]=partNumberString[2][y];
    //now column contains values of 3rd column (with index 2)

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Think about the array size. 2D array means, it's an arrays of array. You have a structure something like this,

    Java Code:
    { element1, element2, element3, element4 }
    Consider the each element. All of that element is also an arrays. You want to access them. M77 described the quite similar thing in the above code.

Similar Threads

  1. Array Reflection: Multi Array Reflection
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-23-2008, 08:08 PM
  2. Array Help
    By bluegreen7hi in forum New To Java
    Replies: 2
    Last Post: 03-28-2008, 02:25 AM
  3. can anyone help... 2d Array
    By Mark1989 in forum New To Java
    Replies: 2
    Last Post: 03-12-2008, 08:59 PM
  4. Would appreciate your help with 2d Array..
    By cloudkicker in forum New To Java
    Replies: 1
    Last Post: 02-11-2008, 02:34 PM
  5. 2D array
    By bluekswing in forum New To Java
    Replies: 2
    Last Post: 01-15-2008, 05:57 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •