Solved

side effect of using setRowSelectionAllowed(false): loss of highlight in selected row

Posted on 2001-07-16
9
364 Views
Last Modified: 2011-09-20
I have defined: JTable dataTable;
and I am using: TableModel tableModel;

to display table rows in the user interface.  When user selects a row, I use:

dataTable.setRowSelectionAllowed(false); to disable selection of any rows in the table and it works.

The problem I have is that as soon as this is executed, the selected row is not highlighted anymore.

disable() method works however, it is deprecated and I don't wnat to use that instead.
0
Comment
Question by:tinav
  • 4
  • 3
  • 2
9 Comments
 
LVL 4

Expert Comment

by:Neutron
ID: 6287034
You say that disable() does it for you?
Try setEnabled( false ) instead...

If this is what you need, it's for free, just delete the question :o)

Greetings,
    Ntr:)
0
 

Author Comment

by:tinav
ID: 6287132
Thanks, it works.  the only problem with this is the row selected is highlighted but, the user can go in the table modle and click on other rows even though the table is now disabled.  I am displaying some data based on the selected row and this way if the user can click on something else, the wrong row is highlighted for the data that is displayed.
0
 
LVL 4

Expert Comment

by:Neutron
ID: 6287237

To disable selection you can subclass JTable to add some new functionality for disabling selections.

So, you don't add instance of JTable to your panel, but add instance of, let's call it TinavJPanel:

-------8<-------file TinavJPanel.java------cut-here-----

import javax.swing.JPanel;

public class TinavJPanel extends JPanel{

private boolean specialDisable=false;

public void changeSelection(int rowIndex, int columnIndex, boolean toggle, boolean extend) {
  if (!specialDisable)
      super.changeSelection( rowIndex, columnIndex, toggle, extend );

public void setSpecialDisable( boolean state ){
  specialDisable=state;
}

}

-------8<-------eof-----------------cut-here-------

In your code where you add JTable to a panel, instantiate a TinavJTable instead using the same parameters in constructor which you were using with JTable.

This might even work, but I didn't test this.

This method 'changeSelection' that is overridden is the only one in JTable that receives "cooked" mouse events for selecting, and implemented like this it is being executed only when you call tab.setSpecialDisable( true ), and not when you set it to false (naturally).

Greetings,
    Ntr:)
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
LVL 4

Accepted Solution

by:
Neutron earned 200 total points
ID: 6287269
Another way to deal with this is to add a selection listener to selection model (with selection MODE set to SINGLE_SELECTION, of course) so you can track when selection has changed, so you can display data of newly selected row...
0
 
LVL 4

Expert Comment

by:Neutron
ID: 6287270
Another way to deal with this is to add a selection listener to selection model (with selection MODE set to SINGLE_SELECTION, of course) so you can track when selection has changed, so you can display data of newly selected row...
0
 

Author Comment

by:tinav
ID: 6287562
For my project, when the user is in add mode I am not supposed to allow the user click on the other rows.  So this may work but, not for me.  

There is a way to place a glass pane on the model to keep all mouse events away from the model.  The user will see what is there but, nothing happens when you click ona  row.

Do you know how to do that?
0
 
LVL 7

Expert Comment

by:Igor Bazarny
ID: 6287731
Hi,

GlassPane is easy to use when you have it available (like in JFrame). Just call frame.getGlassPane().setVisible(true). The problem is that glassPane covers whole JFrame surface, so all your controls will be unavailable to user. If you plan custom glassPane solution, make sure that glassPane is transparent and that it takes mouseEvents first (it's first in containing container's list of children).

Regards,
Igor Bazarny
0
 

Author Comment

by:tinav
ID: 6294467
My frame has four panels.  I need to place the Glass Pane on the first and second panel only.  Do you know how I can do that?  I know you said customize glassPane but, I don't know how to make it cover part of the frame.  Do you have code examples?
0
 
LVL 7

Expert Comment

by:Igor Bazarny
ID: 6295506
Well, it was kind of brainstorming. You can't take existing GlassPane and resize it to cover part of frame, I think. You need to create another container with glassPane/contentPane and use it. I will try to write some code to show that. Or will try to find existing solution.

Regards,
Igor Bazarny
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Application launch issue with Apache Tomcat 5 42
fibonacci ten numbers 4 38
reverse digits of a number using for loop 5 40
expectj telnet failing 5 35
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
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…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
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:

776 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