Solved

making a spread sheet out of a JTable

Posted on 2000-04-19
7
325 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

 

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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

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 …
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
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 tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

856 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