Solved

How to use JTable

Posted on 2006-07-18
7
340 Views
Last Modified: 2010-03-31
Hi Experts,
Please let me know how to rerange the column with of JTable in the code.
I have the default table as below:
STT    Menu   Series     Product  
1          D      12345..   LC27

The leght of series is 14, so I want to rerange the Series column or what the column I need with the width param.

I need to add a check box to cell of rows of JTable
I do as below- see at line 2:

                data[rowIndex][0] = Integer.toString(seriObj.getSeqNumber());

                data[rowIndex][1] =new Boolean(false);   //Bolean value to add a check box to cell

                data[rowIndex][2] = seriObj.getSeriCode();
                data[rowIndex][3] = seriObj.getProductName();

but it cause me the java.lang.ArrayStoreException: java.lang.Boolean exception

Thank you in advance!

It is correct to add a check box to cell? please let me know the way to do this?
0
Comment
Question by:CongUan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
7 Comments
 
LVL 26

Expert Comment

by:ksivananth
ID: 17135792
check the data type of the array!
0
 
LVL 26

Expert Comment

by:ksivananth
ID: 17135794
it should be the type of Object
0
 
LVL 30

Accepted Solution

by:
Mayank S earned 168 total points
ID: 17136093
0
 
LVL 26

Assisted Solution

by:ksivananth
ksivananth earned 166 total points
ID: 17136103
to resize the column width, set the setAutoResizeMode( int ) and pass JTable.AUTO_RESIZE_NEXT_COLUMN | AUTO_RESIZE_SUBSEQUENT_COLUMNS| AUTO_RESIZE_LAST_COLUMN

0
 
LVL 8

Assisted Solution

by:kaliyugkaarjun
kaliyugkaarjun earned 166 total points
ID: 17136276
Using a Basic JTable:

import java.awt.*;
import javax.swing.*;

public class BasicTable extends JFrame {
    public static void main(String args) {
        new BasicTable();
    }

    public BasicTable() {
        super("Basic Table");
        setDefaultCloseOperation(EXIT_ON_CLOSE);

        Container c = getContentPane();

        c.add( new JScrollPane( new JTable() ), BorderLayout.CENTER );

        pack();
        setVisible(true);
    }
}

More Links

http://www.codeguru.com/java/Swing/JTable/index.shtml
http://everything2.com/index.pl?node_id=1682349
http://quicktable.org/jtable/quicktablemain.htm
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question