You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pivot.apache.org by Damir Dezeljin <da...@dezo.org> on 2013/10/18 12:14:41 UTC

How to apply styles to TableView rows

Hello,

Last week I got a task to develop a simple Java application for importing
Excel files into MySQL database. As I didn't have experience with Java GUI,
I did an investigation and I choose Apache Pivot for developing the GUI
toolking / framework; I'll use Apache POI for reading Excel files.

The application I'm developing needs to load in an Excel spreadsheet and
display its data in a data grid format; a subset of displayed data needs to
be highlighted (colored) to denote what data is going to be imported into a
DB.

I figured out the Apache Pivot TableView would meet my requirements for
displaying a data grid. So I created a TablePane in Java and added it to a
ScrollPane defined in a BXML file. Today I'll move also the TableView
definition into Java code as it needs to be dynamic.

Now I'm struggling finding the way how to highlight a certain rows. Various
posts mention the TableView CellRenderer has to be extended; however, I
didn't find the way or an example how to do it.
Can someone help me out with an example or hints how to implement it. In
case I need to extend a TablePane parrent which in my case is ScrollPane or
any other class by defining my own, I would appreciate an example how to
use my own class within a BXML file where all the GUI structure beside the
TableView for data is defined.

Thanks in advance,
 Damir

Re: How to apply styles to TableView rows

Posted by Sandro Martini <sa...@gmail.com>.
Hi Damir,
welcome to Pivot.

A response fro your question could be here:
http://apache-pivot-users.399431.n3.nabble.com/Custom-style-in-table-view-td4021886.html

On the "dynamic table" I remember that somewhere we should have a
minimal sample (from Brendan, some months ago ?), I'll try to remember
where it is and say something if I find ... Roger, do you remember
something ?

Let us know if you have other questions or if you need more info.

Bye,
Sandro

RE: How to apply styles to TableView rows

Posted by "Roger L. Whitcomb" <Ro...@actian.com>.
You have to use “mDataScrollPane.setView(tableView)”.  Even though ScrollPane is a container, it doesn’t support adding children, and so the single scrollable element has to be added as the “view” of the ScrollPane.

 

~Roger

 

From: Damir Dezeljin [mailto:damir.dezeljin@dezo.org] 
Sent: Friday, October 18, 2013 9:47 AM
To: user
Subject: Re: How to apply styles to TableView rows

 

On the way to solving the initial task I bumped in another problem. I can't find the way to display a TableView in a ScrollPane with id="mDataScrollPane" from the Java code. Unfortunately I can't find an example that doesn't use a BXML file.

 

Here is my code:

---- window.bxml ----

<dockable:ContentWindow title="%mainAppTitle" 

    maximized="true" 

     bxml:id="mainWindow" 

     xmlns:bxml="http://pivot.apache.org/bxml" 

     xmlns:content="org.apache.pivot.wtk.content"

     xmlns:dockable="si.dezo.ewn"

     xmlns:collections="org.apache.pivot.collections"

     xmlns="org.apache.pivot.wtk">

  ...

  <content>

    <Border xmlns="org.apache.pivot.wtk" styles="{padding:6}">

      <TablePane>

        <columns>

          <TablePane.Column width="1*"/>

        </columns>

        <TablePane.Row height="1*">

          <Border styles="{color:10}">

            <ScrollPane bxml:id="mDataScrollPane" horizontalScrollBarPolicy="fill" preferredHeight="240" verticalScrollBarPolicy="fill_to_capacity">

            </ScrollPane>

          </Border>

        </TablePane.Row>

      </TablePane>

    </Border>

  </content>

</dockable:ContentWindow>

----

 

---- ContentWindow.java ----

package si.dezo.ewn;

 

...

public class ContentWindow extends Window implements Bindable  {

  @BXML private ScrollPane mDataScrollPane;

 

  public ContentWindow() { return; }

 

  @Override

  public void initialize(Map<String, Object> namespace, URL location, Resources resources) {

    Map<String, String> map = new HashMap<String, String>();

    map.put("nation", "SLO");

    map.put("gold", "20");

 

    List<Map<String, String>> tableData = new ArrayList<Map<String, String>>();

    tableData.add(map);

 

    TableView tableView = new TableView(tableData);

 

    ColumnSequence columns = tableView.getColumns();

    columns.add(new Column("nation", "Država", 100));

    columns.add(new Column("gold", "Zlato", 100));

 

    TableViewHeader header = new TableViewHeader();

    header.setTableView(tableView);

 

    mDataScrollPane.add(tableView);

 

    return;

  }

}

----

 

What am I doing wrong?

 

Thanks,

 Damir

​


Re: How to apply styles to TableView rows

Posted by Damir Dezeljin <da...@dezo.org>.
On the way to solving the initial task I bumped in another problem. I can't
find the way to display a TableView in a ScrollPane with id="mDataScrollPane"
from the Java code. Unfortunately I can't find an example that doesn't use
a BXML file.

Here is my code:
---- window.bxml ----
<dockable:ContentWindow title="%mainAppTitle"
    maximized="true"
     bxml:id="mainWindow"
     xmlns:bxml="http://pivot.apache.org/bxml"
     xmlns:content="org.apache.pivot.wtk.content"
     xmlns:dockable="si.dezo.ewn"
     xmlns:collections="org.apache.pivot.collections"
     xmlns="org.apache.pivot.wtk">
  ...
  <content>
    <Border xmlns="org.apache.pivot.wtk" styles="{padding:6}">
      <TablePane>
        <columns>
          <TablePane.Column width="1*"/>
        </columns>
        <TablePane.Row height="1*">
          <Border styles="{color:10}">
            <ScrollPane bxml:id="mDataScrollPane"
horizontalScrollBarPolicy="fill" preferredHeight="240"
verticalScrollBarPolicy="fill_to_capacity">
            </ScrollPane>
          </Border>
        </TablePane.Row>
      </TablePane>
    </Border>
  </content>
</dockable:ContentWindow>
----

---- ContentWindow.java ----
package si.dezo.ewn;

...
public class ContentWindow extends Window implements Bindable  {
  @BXML private ScrollPane mDataScrollPane;

  public ContentWindow() { return; }

  @Override
  public void initialize(Map<String, Object> namespace, URL location,
Resources resources) {
    Map<String, String> map = new HashMap<String, String>();
    map.put("nation", "SLO");
    map.put("gold", "20");

    List<Map<String, String>> tableData = new ArrayList<Map<String,
String>>();
    tableData.add(map);

    TableView tableView = new TableView(tableData);

    ColumnSequence columns = tableView.getColumns();
    columns.add(new Column("nation", "Država", 100));
    columns.add(new Column("gold", "Zlato", 100));

    TableViewHeader header = new TableViewHeader();
    header.setTableView(tableView);

    mDataScrollPane.add(tableView);

    return;
  }
}
----

What am I doing wrong?

Thanks,
 Damir
​

Re: How to apply styles to TableView rows

Posted by Damir Dezeljin <da...@dezo.org>.
Unfortunately the select doesn't work for me as I'm sure the user will try
to click with a mouse and by doing this the rows will be unselected.

Currently I'm considering adding a new initial row where I'll display an OK
image for rows that will be imported.

Later I may consider reimplementing this to use the renderer.

Thanks for the initial hints and for the good work you're doing at Apache
Pivot. Sincerely,
 Damir
​

RE: How to apply styles to TableView rows

Posted by "Roger L. Whitcomb" <Ro...@actian.com>.
Hi Damir,

                Thanks for using Pivot!  

                Quick suggestion:  can you just “select” the rows you are going to import?  That is very easy to do with methods like “tableView.addSelectedIndex(int)” or “tableView.setSelectedRange(int, int)”.

 

~Roger

 

From: Damir Dezeljin [mailto:damir.dezeljin@dezo.org] 
Sent: Friday, October 18, 2013 3:15 AM
To: user@pivot.apache.org
Subject: How to apply styles to TableView rows

 

Hello,

 

Last week I got a task to develop a simple Java application for importing Excel files into MySQL database. As I didn't have experience with Java GUI, I did an investigation and I choose Apache Pivot for developing the GUI toolking / framework; I'll use Apache POI for reading Excel files.

 

The application I'm developing needs to load in an Excel spreadsheet and display its data in a data grid format; a subset of displayed data needs to be highlighted (colored) to denote what data is going to be imported into a DB.

 

I figured out the Apache Pivot TableView would meet my requirements for displaying a data grid. So I created a TablePane in Java and added it to a ScrollPane defined in a BXML file. Today I'll move also the TableView definition into Java code as it needs to be dynamic.

 

Now I'm struggling finding the way how to highlight a certain rows. Various posts mention the TableView CellRenderer has to be extended; however, I didn't find the way or an example how to do it.

Can someone help me out with an example or hints how to implement it. In case I need to extend a TablePane parrent which in my case is ScrollPane or any other class by defining my own, I would appreciate an example how to use my own class within a BXML file where all the GUI structure beside the TableView for data is defined.

 

Thanks in advance,

 Damir