making a spread sheet out of a JTable

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.......
luinziAsked:
Who is Participating?
 
kylarConnect With a Mentor Commented:
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
 
kylarCommented:
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
 
luinziAuthor Commented:
Do I need to place these code fragments into ny specific methods at all?
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
luinziAuthor Commented:
That sounds too easy..... but it works apart from setSelectionMode(JList.MULTIPLE_INTERVAL_SELECTION); as JList seems to be an unknown variable.
0
 
heyhey_Commented:
what about one more import statement ? :)

import com.sun.java.swing.JList ;
(or
import javax.swing.JList;
)
0
 
kylarCommented:
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
 
luinziAuthor Commented:
Thanks! I got it all working in the end!

Cheers!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.