Results 1 to 3 of 3
  1. #1
    victoryo is offline Member
    Join Date
    Dec 2011
    Posts
    16
    Rep Power
    0

    Default Fill jtable columns

    Hi all.

    Iam trieing to make a JTable. That get filld by 2 ArrayLists.
    The problem is that i want that array list 1 fills column 1 like this.

    1.
    2.
    3.
    4.
    5.
    etc.

    And the other arraylist fills the column beside it.

    My jtable looks like this now!

    Java Code:
                 String[] setColumnIdentifiers = {leg.getNameP1(), leg.getNameP2()};
                 model = new DefaultTableModel(setColumnIdentifiers, 0);
                
                 
                 scoreTable = new JTable(model);
    
                 scoreTable.getTableHeader().setFont( new Font( "Dialog" , Font.BOLD, 13 ));
                 scoreTable.getTableHeader().setReorderingAllowed(false);
                 scoreTable.setForeground(Color.WHITE);
                 scoreTable.setBackground(Color.BLACK);
                 scoreTable.setFont(new Font("Tahoma", 1, 18));
                 scoreTable.setEnabled(false);
                 scoreTable.setFocusable(false);
                 scoreTable.setShowHorizontalLines(false);
                 scoreTable.setShowVerticalLines(false);                
                 
                 scrollPane = new JScrollPane(scoreTable);
                 scrollPane.getViewport().setBackground(Color.BLACK);
                 scrollPane.setBounds(0, 0, 500, 500);
                 right.add(scrollPane);
    Last edited by victoryo; 01-11-2012 at 02:34 PM.

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,932
    Rep Power
    8

    Default Re: Fill jtable columns

    Can't you just call JTable.setValueAt()?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,234
    Rep Power
    7

    Default Re: Fill jtable columns

    The DefaultTableModel only supports a 2-dimensional array or a Vector of Vectors. So you need to copy your data to either one of those objects first.

    Or the other approach is to create a custom table model that uses an ArrayList as is demonstrated in List Table Model Java Tips Weblog.

Similar Threads

  1. Adding Rows to a JTable
    By mlad in forum AWT / Swing
    Replies: 3
    Last Post: 05-04-2011, 02:09 AM
  2. Jtable rows
    By riddhishah28 in forum AWT / Swing
    Replies: 3
    Last Post: 02-18-2011, 06:24 AM
  3. Remove Jtable rows
    By anilkumar_vist in forum Advanced Java
    Replies: 2
    Last Post: 09-17-2010, 08:03 AM
  4. how to fill a jtable with a dropdown menue in each cell
    By dandon_1912 in forum javax.swing
    Replies: 0
    Last Post: 03-04-2009, 12:49 PM
  5. Deleting All rows in the JTable
    By surot in forum New To Java
    Replies: 1
    Last Post: 04-16-2008, 10:44 AM

Posting Permissions

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