Solved

making a spread sheet out of a JTable

Posted on 2000-04-19
7
322 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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
strDist challenge 35 84
mapBully challenge 6 89
wordlen challenge 3 47
github account with ecipse 1 17
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…
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
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 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:

705 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

18 Experts available now in Live!

Get 1:1 Help Now