2 Replies - 309 Views - Last Post: 08 February 2010 - 06:32 PM Rate Topic: -----

#1 bcranger  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 252
  • View blog
  • Posts: 1,199
  • Joined: 01-February 10

JTables and 2-D Arrays Problem

Posted 08 February 2010 - 05:18 PM

my code is the following...

I cannot seem to make a JTable correctly, especially since 2-D arrays are not assigning values as they should be...

Anyone got a solution?

I'm trying to get a table of items and their characteristics:


public void showInventory()
  {
    JFrame inventoryFrame = new JFrame("Inventory");
    inventoryFrame.setSize(400,400);
    inventoryFrame.setLocation(300,300);
    
    String[] columnNames = {"Item Number","Item Name", "Item Price", "Item Discount"};
    
    Object[][] data = new Object[numItems][numItems];
    
    for(int i = 0; i < numItems; i++)
    {
      for(int j = 0; j < numItems; j++)
      {
        data[i][j] = item[i].getItemNumber() + item[j].getItemName();
      }
    }

    JTable inventoryTable = new JTable(data,columnNames);
    
    inventoryFrame.add(inventoryTable);
    
    inventoryFrame.setVisible(true);
  }




Is This A Good Question/Topic? 0
  • +

Replies To: JTables and 2-D Arrays Problem

#2 japanir  Icon User is offline

  • jaVanir
  • member icon

Reputation: 1010
  • View blog
  • Posts: 3,025
  • Joined: 20-August 09

Re: JTables and 2-D Arrays Problem

Posted 08 February 2010 - 05:38 PM

what do you expect to get as an output?
what do you get instead? any errors maybe?
please provide some more information, so those who are willing to help will fully understand the problem. :)
Was This Post Helpful? 0
  • +
  • -

#3 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8329
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: JTables and 2-D Arrays Problem

Posted 08 February 2010 - 06:32 PM

One thing for sure/
For a JTable to show its coumn name the JTable should be in a ScrolPane so
 JTable inventoryTable = new JTable(data,columnNames);        
 inventoryFrame.add(inventoryTable);  


should be
 JTable inventoryTable = new JTable(data,columnNames);        
 inventoryFrame.add(new JScrollPane(inventoryTable));  


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1