Solved

How to use JTable

Posted on 2006-07-18
7
328 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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Suggested Solutions

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 …
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

696 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