To select a row with user-defined color + TreeTable

This forum is used by users to request and discuss new product features. Please do not use this forum for technical support including bug reports.

Moderator: JIDE Support

Forum rules
Product suggestions only. Please do not use this forum for technical support including bug reports.

To select a row with user-defined color + TreeTable

Postby Nachiyappan » Tue Dec 08, 2009 4:12 am

Hi,

I need to give different color to differenciate a normal row selection and selecting a row while getting update.

Can you please give me a solution.

Thanks & Regards
Nachiyappan.
Nachiyappan
 
Posts: 32
Joined: Tue Oct 06, 2009 9:10 pm

Re: To select a row with user-defined color + TreeTable

Postby JIDE Support » Tue Dec 08, 2009 8:42 am

Please try override JideTable#changeSelection() to mark the rows that selected by your customers. Next step, please customize your cell renderer to give the rows a differenct selection color.

Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Re: To select a row with user-defined color + TreeTable

Postby Nachiyappan » Tue Dec 08, 2009 8:44 pm

Can you please give me any sample code..

Thanks in advance
Nachiyappan
 
Posts: 32
Joined: Tue Oct 06, 2009 9:10 pm

Re: To select a row with user-defined color + TreeTable

Postby JIDE Support » Tue Dec 08, 2009 10:11 pm

The following codes are just a sample to show the idea. To achieve your ultimate goal, you would control more carefully than that.
Code: Select all
            int _row = -1;
            @Override
            public void changeSelection(int row, int column, boolean toggle, boolean expand) {
                // put the row in your list.
                _row = row;
                super.changeSelection(row, column, toggle, expand);
            }

            @Override
            public Component prepareRenderer(TableCellRenderer renderer, int row, int column) {
                Component component = super.prepareRenderer(renderer, row, column);
                if (_row == row) {
                    component.setForeground(Color.red);
                }
                return component;
            }

Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Re: To select a row with user-defined color + TreeTable

Postby Nachiyappan » Tue Dec 15, 2009 6:51 am

Hi, This solution is working only if I select a row manually.

But If I need to select a row explicitly. What should I do?

As of now, I am selecting a row by using getTable().getSelectionModel().setSelectionInterval(rowIndex, rowIndex);

Please let me know the solution.

Thanks
Nachiyappan
 
Posts: 32
Joined: Tue Oct 06, 2009 9:10 pm

Re: To select a row with user-defined color + TreeTable

Postby JIDE Support » Tue Dec 15, 2009 8:08 am

Please allow me repeat your original request that you want to differentiate a normal row selection and selecting a row while getting update. Both scenario will eventually invoke yourTable#getSelectionModel()#setSelectionInterval(). So we have to mark the rows before that method invocation to achieve your goal. That's how I come up with the solution in previous post. If you want to invoke that method to select a row, is it possible for you to mark the rows before you invoke that method?

Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Re: To select a row with user-defined color + TreeTable

Postby Nachiyappan » Tue Dec 15, 2009 9:15 pm

Let me clearly tell the problem:

I want to differentiate a normal row selection by user and selecting a row explicitly while getting update not by user selection.

For normal row selection, the row is highlighted by blue color. While I am selecting a row explicitly by using myTable.getSelectionModel().setSelectionInterval(), also the row's selection color is blue. But I want to highlight row using red color.

As you said I overrided changeSelection() & prepareRenderer() method in TreeTable. The selection what I set is working. But, Initially it selects the row in blue color, while I select a row, it changes to red color and retains forever. But if next row getting highlight, the highlight should disappear... Also the row selection should be in red not in blue color intially.

Hope you get my problem clearly. Else please let me know, I will explain.

Thanks
Nachiyappan
 
Posts: 32
Joined: Tue Oct 06, 2009 9:10 pm

Re: To select a row with user-defined color + TreeTable

Postby JIDE Support » Tue Dec 15, 2009 10:10 pm

Got you. I mistook the meaning of "update". I thought you were talking about selection persistence after table model events so I asked you to override those two methods.

Now I started to think if your original requirement makes sense. No matter the selection is from selectionModel's call or from user action, eventually it will go to JTable#changeSelection. And JTable#changeSelection can't tell whether the selection is from user action or from code. So overriding changeSelection will not work. The renderer selection highlight depends on the selection model's state. Again there is no difference in the selection model whether the selection is from user action or from code. So try to override prepareRenderer will end up in nowhere too.

I assume your requirement is to somehow highlight certain rows, not necessarily mess up the table selection. What I am going to suggest you is to use CellStyle feature we provided. You just need to add background style to the table to achieve the feature. It is easier and well supported and documented in JIDE Grids. Please refer to JIDE Grids Developer Guide and several examples on cell style to understand how it works.

Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am


Return to Product Suggestions

Who is online

Users browsing this forum: No registered users and 9 guests