You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pivot.apache.org by prophe <au...@cargosoft.ru> on 2011/09/15 17:48:53 UTC

Cell selection in TableView

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.

Re: Cell selection in TableView

Posted by Roger and Beth Whitcomb <Ro...@rbwhitcomb.com>.
Replace the "setText(null)" with "setText("")"

~Roger

On 2/24/14 9:47 PM, Ripgiblet wrote:
> Actually could not get it to work, maybe not compatible with current pivot...
> Maybe there has been a change to the setText class, so it throws an error on
> a null value...
>
> java.lang.IllegalArgumentException
> 	at org.apache.pivot.wtk.Label.setText(Label.java:127)
> 	at
> com.ott.fazet.wtk.content.TableViewCellRenderer.render(TableViewCellRenderer.java:61)
> 	at
> com.ott.fazet.wtk.skin.terra.TerraFazetTableViewSkin.calculateFixedRowHeight(TerraFazetTableViewSkin.java:311)
> 	at
> com.ott.fazet.wtk.skin.terra.TerraFazetTableViewSkin.layout(TerraFazetTableViewSkin.java:275)
> 	at org.apache.pivot.wtk.Component.layout(Component.java:1992)
> 	at org.apache.pivot.wtk.Component.validate(Component.java:1983)
> 	at org.apache.pivot.wtk.Container.layout(Container.java:355)
> 	at org.apache.pivot.wtk.Component.validate(Component.java:1983)
> 	at org.apache.pivot.wtk.Container.layout(Container.java:355)
> 	at org.apache.pivot.wtk.Component.validate(Component.java:1983)
> 	at org.apache.pivot.wtk.Component.setVisible(Component.java:1592)
> 	at org.apache.pivot.wtk.Container.setVisible(Container.java:346)
> 	at
> org.apache.pivot.wtk.skin.CardPaneSkin.selectedIndexChanged(CardPaneSkin.java:787)
> 	at
> org.apache.pivot.wtk.CardPane$CardPaneListenerList.selectedIndexChanged(CardPane.java:52)
> 	at org.apache.pivot.wtk.CardPane.setSelectedIndex(CardPane.java:90)
> 	at
> org.apache.pivot.wtk.skin.CardPaneSkin.componentInserted(CardPaneSkin.java:659)
> 	at
> org.apache.pivot.wtk.Container$ContainerListenerList.componentInserted(Container.java:41)
> 	at org.apache.pivot.wtk.Container.insert(Container.java:167)
> 	at org.apache.pivot.wtk.CardPane.insert(CardPane.java:111)
> 	at org.apache.pivot.wtk.Container.add(Container.java:138)
> 	at org.apache.pivot.wtk.Container.add(Container.java:34)
> 	at
> org.apache.pivot.beans.BXMLSerializer.processEndElement(BXMLSerializer.java:1206)
> 	at
> org.apache.pivot.beans.BXMLSerializer.readObject(BXMLSerializer.java:448)
> 	at
> org.apache.pivot.beans.BXMLSerializer.processStartElement(BXMLSerializer.java:910)
> 	at
> org.apache.pivot.beans.BXMLSerializer.readObject(BXMLSerializer.java:443)
> 	at
> org.apache.pivot.beans.BXMLSerializer.readObject(BXMLSerializer.java:634)
> 	at
> org.apache.pivot.beans.BXMLSerializer.readObject(BXMLSerializer.java:589)
> 	at
> org.apache.pivot.beans.BXMLSerializer.readObject(BXMLSerializer.java:550)
> 	at mrc.phoenix.TRN.TRNGUIPivot.<init>(TRNGUIPivot.java:85)
>
> I will have a look at the code, and see if I can see why it is trying to
> setText...
>
> regards,
>
>
>
> --
> View this message in context: http://apache-pivot-users.399431.n3.nabble.com/Cell-selection-in-TableView-tp3339330p4022889.html
> Sent from the Apache Pivot - Users mailing list archive at Nabble.com.
>
>


Re: Cell selection in TableView

Posted by Ripgiblet <ma...@mrchambers.org>.
Actually could not get it to work, maybe not compatible with current pivot...
Maybe there has been a change to the setText class, so it throws an error on
a null value...

java.lang.IllegalArgumentException
	at org.apache.pivot.wtk.Label.setText(Label.java:127)
	at
com.ott.fazet.wtk.content.TableViewCellRenderer.render(TableViewCellRenderer.java:61)
	at
com.ott.fazet.wtk.skin.terra.TerraFazetTableViewSkin.calculateFixedRowHeight(TerraFazetTableViewSkin.java:311)
	at
com.ott.fazet.wtk.skin.terra.TerraFazetTableViewSkin.layout(TerraFazetTableViewSkin.java:275)
	at org.apache.pivot.wtk.Component.layout(Component.java:1992)
	at org.apache.pivot.wtk.Component.validate(Component.java:1983)
	at org.apache.pivot.wtk.Container.layout(Container.java:355)
	at org.apache.pivot.wtk.Component.validate(Component.java:1983)
	at org.apache.pivot.wtk.Container.layout(Container.java:355)
	at org.apache.pivot.wtk.Component.validate(Component.java:1983)
	at org.apache.pivot.wtk.Component.setVisible(Component.java:1592)
	at org.apache.pivot.wtk.Container.setVisible(Container.java:346)
	at
org.apache.pivot.wtk.skin.CardPaneSkin.selectedIndexChanged(CardPaneSkin.java:787)
	at
org.apache.pivot.wtk.CardPane$CardPaneListenerList.selectedIndexChanged(CardPane.java:52)
	at org.apache.pivot.wtk.CardPane.setSelectedIndex(CardPane.java:90)
	at
org.apache.pivot.wtk.skin.CardPaneSkin.componentInserted(CardPaneSkin.java:659)
	at
org.apache.pivot.wtk.Container$ContainerListenerList.componentInserted(Container.java:41)
	at org.apache.pivot.wtk.Container.insert(Container.java:167)
	at org.apache.pivot.wtk.CardPane.insert(CardPane.java:111)
	at org.apache.pivot.wtk.Container.add(Container.java:138)
	at org.apache.pivot.wtk.Container.add(Container.java:34)
	at
org.apache.pivot.beans.BXMLSerializer.processEndElement(BXMLSerializer.java:1206)
	at
org.apache.pivot.beans.BXMLSerializer.readObject(BXMLSerializer.java:448)
	at
org.apache.pivot.beans.BXMLSerializer.processStartElement(BXMLSerializer.java:910)
	at
org.apache.pivot.beans.BXMLSerializer.readObject(BXMLSerializer.java:443)
	at
org.apache.pivot.beans.BXMLSerializer.readObject(BXMLSerializer.java:634)
	at
org.apache.pivot.beans.BXMLSerializer.readObject(BXMLSerializer.java:589)
	at
org.apache.pivot.beans.BXMLSerializer.readObject(BXMLSerializer.java:550)
	at mrc.phoenix.TRN.TRNGUIPivot.<init>(TRNGUIPivot.java:85)

I will have a look at the code, and see if I can see why it is trying to
setText...

regards,



--
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/Cell-selection-in-TableView-tp3339330p4022889.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Re: Cell selection in TableView

Posted by Ripgiblet <ma...@mrchambers.org>.
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.



--
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/Cell-selection-in-TableView-tp3339330p4022888.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Re: Cell selection in TableView

Posted by influence160 <ti...@gmail.com>.
This is a custom TableView for Apache Pivot that allow cells selection 

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

<http://apache-pivot-users.399431.n3.nabble.com/file/n4022540/anDx3ra.png> 



--
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/Cell-selection-in-TableView-tp3339330p4022540.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Re: Cell selection in TableView

Posted by prophe <au...@cargosoft.ru>.
But I don't know why it isn't work properly =)

-----
Thank you!
--
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/Cell-selection-in-TableView-tp3339330p3339896.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Re: Cell selection in TableView

Posted by Greg Brown <gk...@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.


Re: Cell selection in TableView

Posted by prophe <au...@cargosoft.ru>.
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.

Re: Cell selection in TableView

Posted by Greg Brown <gk...@verizon.net>.
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.


Re: Cell selection in TableView

Posted by prophe <au...@cargosoft.ru>.
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!
--
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/Cell-selection-in-TableView-tp3339330p3342104.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Re: Cell selection in TableView

Posted by prophe <au...@cargosoft.ru>.
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.

Re: Cell selection in TableView

Posted by Greg Brown <gk...@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.


Re: Cell selection in TableView

Posted by prophe <au...@cargosoft.ru>.
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.

Re: Cell selection in TableView

Posted by Greg Brown <gk...@verizon.net>.
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.


Re: Cell selection in TableView

Posted by prophe <au...@cargosoft.ru>.
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.

Re: Cell selection in TableView

Posted by Greg Brown <gk...@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.


Re: Cell selection in TableView

Posted by prophe <au...@cargosoft.ru>.
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.

Re: Cell selection in TableView

Posted by Greg Brown <gk...@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.


Re: Cell selection in TableView

Posted by prophe <au...@cargosoft.ru>.
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.

Re: Cell selection in TableView

Posted by Greg Brown <gk...@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.


Re: Cell selection in TableView

Posted by prophe <au...@cargosoft.ru>.
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.

Re: Cell selection in TableView

Posted by Greg Brown <gk...@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.