Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2001-07-16
9
Medium Priority
?
415 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Accepted Solution

by:
Neutron earned 800 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

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…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
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 how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

604 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