Solved

making a spread sheet out of a JTable

Posted on 2000-04-19
7
326 Views
Last Modified: 2012-05-04
I am using JDK1. 2 to create a program that uses SWING to generate a JTable. How would I go about manipulating the JTable so that I can select different selection combinations of rows and columns within the JTable like on a standard spread sheet.

At present the JTable only allows me to select entire rows.

Thanks.......
0
Comment
Question by:luinzi
  • 3
  • 3
7 Comments
 
LVL 4

Expert Comment

by:kylar
ID: 2732621
try calling setCellSelectionEnabled(true), setColumnSelectionAllowed(true), setRowSelectionAllowed(true) and setSelectionMode(JList.MULTIPLE_INTERVAL_SELECTION) on your table. That will allow you to select multiple non-contigious sections.

Kylar
0
 

Author Comment

by:luinzi
ID: 2732630
Do I need to place these code fragments into ny specific methods at all?
0
 
LVL 4

Accepted Solution

by:
kylar earned 50 total points
ID: 2732640
Call them on the table itself after you create it:

JTable mytable = new JTable();

mytable.setCellSelectionEnabled(true);
mytable.setSelectionMode(JList.MULTIPLE_INTERVAL_SELECTION);
mytable.setColumnSelectionAllowed(true);


like that.

Kylar
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:luinzi
ID: 2732674
That sounds too easy..... but it works apart from setSelectionMode(JList.MULTIPLE_INTERVAL_SELECTION); as JList seems to be an unknown variable.
0
 
LVL 16

Expert Comment

by:heyhey_
ID: 2733424
what about one more import statement ? :)

import com.sun.java.swing.JList ;
(or
import javax.swing.JList;
)
0
 
LVL 4

Expert Comment

by:kylar
ID: 2738105
Heh, yeah. that would work. You can substitute setSelectionMode(2) if you're using JDK1.2.

If the stuff all works like you wanted, why not grade the question?

Kylar
0
 

Author Comment

by:luinzi
ID: 2739055
Thanks! I got it all working in the end!

Cheers!
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
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 will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

763 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