Cell selection in TableView

classic Classic list List threaded Threaded
22 messages Options
12
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Cell selection in TableView

prophe
Hi, all. I want to realize a cell selection in table View. I try to rewrite TerraTableViewSkin, but some my cells is never highlighted and I can't understand why... I add a few line of code in TerraTableViewSkin in paint method:

..................................................................
 // Paint the cells
            columnX = 0;

            for (int columnIndex = 0, columnCount = columns.getLength(); columnIndex < columnCount; columnIndex++) {
           

            boolean cellHighlighted = (columnIndex==highlightColumnIndex);
           
            Color cellBackgroundColor = null;
           
                if (cellHighlighted && rowHighlighted){
                System.out.println("cellBackgroundColor");
                    cellBackgroundColor = (tableView.isFocused())
                            ? this.selectionCellBackgroundColor : inactiveCellSelectionBackgroundColor;
                }
               
                int columnWidth = columnWidths.get(columnIndex);
               
                if (cellBackgroundColor!=null){
                    graphics.setPaint(cellBackgroundColor);
                    graphics.fillRect(columnX, rowY, columnWidth, rowHeight);
                }
           
                TableView.Column column = columns.get(columnIndex);
..........................................................................................
and in mouseMove method:

    @Override
    public boolean mouseMove(Component component, int x, int y) {
        boolean consumed = super.mouseMove(component, x, y);

        TableView tableView = (TableView)getComponent();

        int previousHighlightRowIndex = this.highlightRowIndex;
        highlightRowIndex = getRowAt(y);
       
        int previousHighlightColumnIndex = this.highlightColumnIndex;
        highlightColumnIndex = getColumnAt(x);

        if (previousHighlightRowIndex != highlightRowIndex
            && tableView.getSelectMode() != TableView.SelectMode.NONE
            && showHighlight) {
            if (previousHighlightRowIndex != -1) {
                repaintComponent(getRowBounds(previousHighlightRowIndex));
            }

            if (highlightRowIndex != -1 ) {
                repaintComponent(getRowBounds(highlightRowIndex));
            }
        }
       
        if (highlightColumnIndex != previousHighlightColumnIndex
                && showHighlight){
       
        repaintComponent(getRowBounds(previousHighlightColumnIndex));
        System.out.println("column index - " + highlightColumnIndex);
       
        if (highlightColumnIndex != -1) {
                repaintComponent(getRowBounds(highlightColumnIndex));
            }
        }

        return consumed;
    }

But some of my cells is never highlighted on mouse move... My code to look at and to test
here
Please help me...


Thank you!
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Cell selection in TableView

gk_brown@verizon.net
TableView isn't really designed to support single-cell selection, though it is possible to implement a single-cell editor.

On Sep 15, 2011, at 11:48 AM, prophe wrote:

> Hi, all. I want to realize a cell selection in table View. I try to rewrite
> TerraTableViewSkin, but some my cells is never highlighted and I can't
> understand why... I add a few line of code in TerraTableViewSkin in paint
> method:
>
> ..................................................................
> // Paint the cells
>            columnX = 0;
>
>            for (int columnIndex = 0, columnCount = columns.getLength();
> columnIndex < columnCount; columnIndex++) {
>            
>
>             boolean cellHighlighted = (columnIndex==highlightColumnIndex);
>            
>             Color cellBackgroundColor = null;
>            
>                if (cellHighlighted && rowHighlighted){
>                 System.out.println("cellBackgroundColor");
>                    cellBackgroundColor = (tableView.isFocused())
>                            ? this.selectionCellBackgroundColor :
> inactiveCellSelectionBackgroundColor;
>                }
>
>                int columnWidth = columnWidths.get(columnIndex);
>
>                if (cellBackgroundColor!=null){
>                    graphics.setPaint(cellBackgroundColor);
>                    graphics.fillRect(columnX, rowY, columnWidth,
> rowHeight);
>                }
>            
>                TableView.Column column = columns.get(columnIndex);
> ..........................................................................................
> and in mouseMove method:
>
>    @Override
>    public boolean mouseMove(Component component, int x, int y) {
>        boolean consumed = super.mouseMove(component, x, y);
>
>        TableView tableView = (TableView)getComponent();
>
>        int previousHighlightRowIndex = this.highlightRowIndex;
>        highlightRowIndex = getRowAt(y);
>
>        int previousHighlightColumnIndex = this.highlightColumnIndex;
>        highlightColumnIndex = getColumnAt(x);
>
>        if (previousHighlightRowIndex != highlightRowIndex
>            && tableView.getSelectMode() != TableView.SelectMode.NONE
>            && showHighlight) {
>            if (previousHighlightRowIndex != -1) {
>                repaintComponent(getRowBounds(previousHighlightRowIndex));
>            }
>
>            if (highlightRowIndex != -1 ) {
>                repaintComponent(getRowBounds(highlightRowIndex));
>            }
>        }
>
>        if (highlightColumnIndex != previousHighlightColumnIndex
>                && showHighlight){
>        
>         repaintComponent(getRowBounds(previousHighlightColumnIndex));
>         System.out.println("column index - " + highlightColumnIndex);
>        
>         if (highlightColumnIndex != -1) {
>                repaintComponent(getRowBounds(highlightColumnIndex));
>            }
>        }
>
>        return consumed;
>    }
>
> But some of my cells is never highlighted on mouse move... My code to look
> at and to test
> http://perdunov.net/pivotcellteable.rar here
> Please help me...
>
>
>
>
> -----
> Thank you!
> --
> View this message in context: http://apache-pivot-users.399431.n3.nabble.com/Cell-selection-in-TableView-tp3339330p3339330.html
> Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Cell selection in TableView

prophe
But I'm really need a cell selection in table view like this:

Is it possible? Or I need to write my custom table view?
How can I to do that? Can you help me?
Thank you!
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Cell selection in TableView

gk_brown@verizon.net
I guess it depends on what you need to do. TableView's selection model is row-based, not cell-based. What does your app need to do when you select a cell?

On Sep 15, 2011, at 12:20 PM, prophe wrote:

> But I'm really need a cell selection in table view like this:
> http://apache-pivot-users.399431.n3.nabble.com/file/n3339433/cell.jpg 
> Is it possible? Or I need to write my custom table view?
> How can I to do that? Can you help me?
>
> -----
> Thank you!
> --
> View this message in context: http://apache-pivot-users.399431.n3.nabble.com/Cell-selection-in-TableView-tp3339330p3339433.html
> Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Cell selection in TableView

prophe
It needs just select a cell, and highlight row and column which contains this cell(like on the picture).  When row is selected I need to know its position in the table (rowIndex and columnIndex). When I select it I want to navigate with keypad to adjacent cells (just highlight them). And when mouse is over the cell it must just highlight the cell. And I want to continue select a row too, to obtain the data from this row.
Thank you!
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Cell selection in TableView

gk_brown@verizon.net
OK. I think you could probably do this by writing a cell editor that doesn't actually edit its contents. See the TableView row editor demo for an example.

On Sep 15, 2011, at 2:02 PM, prophe wrote:

> It needs just select a cell, and highlight row and column which contains this
> cell(like on the picture).  When row is selected I need to know its position
> in the table (rowIndex and columnIndex). When I select it I want to navigate
> with keypad to adjacent cells (just highlight them). And when mouse is over
> the cell it must just highlight the cell. And I want to continue select a
> row too, to obtain the data from this row.
>
> -----
> Thank you!
> --
> View this message in context: http://apache-pivot-users.399431.n3.nabble.com/Cell-selection-in-TableView-tp3339330p3339733.html
> Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Cell selection in TableView

prophe
Ok, tomorrow I'll try to do this. But how can I highlight the column that contains selected cell?
Thank you!
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Cell selection in TableView

gk_brown@verizon.net
You may need to do this in your cell renderer.

On Sep 15, 2011, at 2:32 PM, prophe wrote:

> Ok, tomorrow I'll try to do this. But how can I highlight the column that
> contains selected cell?
>
> -----
> Thank you!
> --
> View this message in context: http://apache-pivot-users.399431.n3.nabble.com/Cell-selection-in-TableView-tp3339330p3339781.html
> Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Cell selection in TableView

prophe
But why I can not do it in my custom table view skin? I've posted a code where I've almost succeeded to highlight the cell on mouse over event.
Thank you!
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Cell selection in TableView

prophe
But I don't know why it isn't work properly =)
Thank you!
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Cell selection in TableView

gk_brown@verizon.net
In reply to this post by prophe
You probably can, but writing a skin is a lot more involved than writing a renderer.

On Sep 15, 2011, at 3:09 PM, prophe wrote:

> But why I can not do it in my custom table view skin? I've posted a code
> where I've almost succeeded to highlight the cell on mouse over event.
>
> -----
> Thank you!
> --
> View this message in context: http://apache-pivot-users.399431.n3.nabble.com/Cell-selection-in-TableView-tp3339330p3339894.html
> Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Cell selection in TableView

prophe
Ok, I look at TableViewCellRenderer.... I should extend this renderer to write my own? And how can I highlight column and cell (on mouse over) with renderer? I see only:

    public void render(Object row, int rowIndex, int columnIndex,
        TableView tableView, String columnName,
        boolean selected, boolean highlighted, boolean disabled);

Can you give me please a short example that I can understand an idea?
Thank you for your help!

Thank you!
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Cell selection in TableView

gk_brown@verizon.net
Unless you modify the skin, you won't be able to highlight an individual cell on mouse-over, but you can use the renderer to paint a "selected" state for a column. One way to do this would be to create a subclass of TableView.Column and add a boolean "selected" property. Then your renderer can get a reference to the column and set an appropriate background color when "selected" = true.

Though you can't easily highlight the cell as the mouse moves over it, you can highlight the cell when the user clicks on it, since this will invoke the editor.

On Sep 16, 2011, at 3:48 AM, prophe wrote:

> Ok, I look at TableViewCellRenderer.... I should extend this renderer to
> write my own? And how can I highlight column and cell (on mouse over) with
> renderer? I see only:
>
>    public void render(Object row, int rowIndex, int columnIndex,
>        TableView tableView, String columnName,
>        boolean selected, boolean highlighted, boolean disabled);
>
> Can you give me please a short example that I can understand an idea?
> Thank you for your help!
>
>
>
> -----
> Thank you!
> --
> View this message in context: http://apache-pivot-users.399431.n3.nabble.com/Cell-selection-in-TableView-tp3339330p3341276.html
> Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Cell selection in TableView

prophe
Oh, I understand you. But in which class and method boolean "selected" property can be set to true of false? Where and how can I do that? mouseOver method is in the skin...
Thank you!
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Cell selection in TableView

prophe
I've rewrote table view skin. And my table works as needed. But I think you solution is gooder. That's why I pose you questions.) And thank you for your help!
Thank you!
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Cell selection in TableView

gk_brown@verizon.net
In reply to this post by prophe
You'll need to create a custom subclass of TableView.Column and add a "selected" property to it.

On Sep 16, 2011, at 10:37 AM, prophe wrote:

> Oh, I understand you. But in which class and method boolean "selected"
> property can be set to true of false? Where and how can I do that? mouseOver
> method is in the skin...
>
> -----
> Thank you!
> --
> View this message in context: http://apache-pivot-users.399431.n3.nabble.com/Cell-selection-in-TableView-tp3339330p3342094.html
> Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Cell selection in TableView

prophe
This is I understand. I mean where and how this property can be changed? In my renderer I can do column.getSelected()... But If while creation it is setted to "false" and don't change? I always get "false". And I ask where property of Column "selected" is changed?
Thank you!
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Cell selection in TableView

gk_brown@verizon.net
That is up to your app, though I imagine it would be triggered by some user action such as clicking on a column header.

On Sep 16, 2011, at 10:53 AM, prophe wrote:

> This is I understand. I mean where and how this property can be changed? In
> my renderer I can do column.getSelected()... But If while creation it is
> setted to "false" and don't change? I always get "false". And I ask where
> property of Column "selected" is changed?
>
> -----
> Thank you!
> --
> View this message in context: http://apache-pivot-users.399431.n3.nabble.com/Cell-selection-in-TableView-tp3339330p3342134.html
> Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Cell selection in TableView

influence160
In reply to this post by prophe
This is a custom TableView for Apache Pivot that allow cells selection

https://github.com/influence160/fazet-pivot

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Cell selection in TableView

Ripgiblet
I got to the bottom of this page feeling a bit depressed that this does not exist and found your Tableview with cell selection and went Yippeee!!!

Thanks good work;]

regards,
Mark.
12
Loading...