Solved

How to use JTable

Posted on 2006-07-18
7
284 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
  • 3
7 Comments
 
LVL 26

Expert Comment

by:ksivananth
Comment Utility
check the data type of the array!
0
 
LVL 26

Expert Comment

by:ksivananth
Comment Utility
it should be the type of Object
0
 
LVL 30

Accepted Solution

by:
mayankeagle earned 168 total points
Comment Utility
0
 
LVL 26

Assisted Solution

by:ksivananth
ksivananth earned 166 total points
Comment Utility
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
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now