Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to use JTable

Posted on 2006-07-18
7
Medium Priority
?
362 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 672 total points
ID: 17136093
0
 
LVL 26

Assisted Solution

by:ksivananth
ksivananth earned 664 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 664 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
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…
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…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Suggested Courses

610 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