Solved

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

Posted on 2001-07-16
9
390 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SequenceInputStream example 3 34
spring maven example issues 3 95
Java ArrayList and if statement 2 53
Firefox and firebub 5 23
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…
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 …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Suggested Courses

739 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