selected cell in SpreadSheetView

490 views
Skip to first unread message

ettien koua

unread,
Oct 28, 2017, 7:52:35 AM10/28/17
to ControlsFX
I tried to change the color of the border of the cell when the cell is selected in another color but it has no effect.Here is the next piece of code used:

.spreadsheet-cell.my_cell:selected
{
-fx-border-color:red;
}
selected.JPG

samir.ha...@gmail.com

unread,
Oct 30, 2017, 5:37:07 AM10/30/17
to ControlsFX
Hi ,

Could you try that :
.spreadsheet-cell.my_cell:filled:selected ,
.spreadsheet-cell.my_cell:filled:focused:selected,
.spreadsheet-cell.my_cell:filled:focused:selected:hover

Sometime, the "selected" pseudo class isn't enough because other pseudo class are applying.

Regards,
Message has been deleted

ettien koua

unread,
Oct 30, 2017, 8:44:17 AM10/30/17
to ControlsFX
I tried.But it does not work

samir.ha...@gmail.com

unread,
Oct 30, 2017, 9:08:04 AM10/30/17
to ControlsFX
I suggest your post herewith proper formatting an SSCCE so that I can investigate where the issue is.

Regards,

ettien koua

unread,
Oct 30, 2017, 1:32:06 PM10/30/17
to ControlsFX
Ok

ettien koua

unread,
Oct 31, 2017, 10:27:39 AM10/31/17
to ControlsFX
In main.java
package application;

import org.controlsfx.control.spreadsheet.GridBase;
import org.controlsfx.control.spreadsheet.SpreadsheetCell;
import org.controlsfx.control.spreadsheet.SpreadsheetCellType;
import org.controlsfx.control.spreadsheet.SpreadsheetView;

import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.layout.AnchorPane;

public class Main extends Application {
    @Override
    public void start(Stage primaryStage) {
        try {
            // I create a sample grid
            int rowCount = 100;
            int columnCount = 40;
            GridBase grid = new GridBase(rowCount, columnCount);

            ObservableList<ObservableList<SpreadsheetCell>> rows = FXCollections.observableArrayList();

            // header row
            final ObservableList<SpreadsheetCell> listh1 = FXCollections.observableArrayList();
            final ObservableList<SpreadsheetCell> listh2 = FXCollections.observableArrayList();

            // add first column value
            int rowIndex = 0;
            listh1.add(SpreadsheetCellType.STRING.createCell(rowIndex++, 0, 1, 1, "en tete 1"));
            listh2.add(SpreadsheetCellType.STRING.createCell(rowIndex++, 0, 1, 1, "en tete 1"));

            for (int column = 1; column < grid.getColumnCount(); column++) {

                listh1.add(SpreadsheetCellType.STRING.createCell(rowIndex, column, 1, 1, ""));
                listh2.add(SpreadsheetCellType.STRING.createCell(rowIndex, column, 1, 1, ""));

            }
            rows.add(listh1);
            rows.add(listh2);

            for (int row = 0; row < 1; row++) {
                final ObservableList<SpreadsheetCell> list = FXCollections.observableArrayList();
                list.add(SpreadsheetCellType.STRING.createCell(rowIndex, 0, 1, 1,
                        "+Categorie lhkkj:h:jhn:ljkn:kj,kkljklj!kjk:!kmkmlkk:!k:klkljjklj:" + rowIndex));

                for (int column = 1; column < grid.getColumnCount(); column++) {

                   // System.out.println(column);
                    list.add(SpreadsheetCellType.STRING.createCell(rowIndex, column, 1, 1, ""));

                }
                rows.add(list);

                for (int k = 0; k < 5; k++) {
                    rowIndex++;
                    final ObservableList<SpreadsheetCell> list2 = FXCollections.observableArrayList();
                    list2.add(SpreadsheetCellType.STRING.createCell(rowIndex, 0, 1, 1, "   -Sous Categorie"));
                    for (int column = 1; column < grid.getColumnCount(); column++) {
                        SpreadsheetCell  cell = SpreadsheetCellType.INTEGER.createCell(rowIndex, column, 1, 1, 1);
                        cell.getStyleClass().add("childCatValue");
                        list2.add(SpreadsheetCellType.INTEGER.createCell(rowIndex, column, 1, 1, 1));

                    }
                    rows.add(list2);
                }
                rowIndex++;

            }

            grid.setRows(rows);

            SpreadsheetView spv = new SpreadsheetView(grid);
            spv.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
            spv.getFixedRows().addAll(0, 1);
            spv.getColumns().get(0).setFixed(true);
            //spv.setEditable(false);
            spv.setShowRowHeader(false);
            spv.setShowColumnHeader(false);

            AnchorPane root = new AnchorPane();
            spv.prefHeightProperty().bind(root.heightProperty());
            spv.prefWidthProperty().bind(root.widthProperty());
            root.getChildren().add(spv);

            Scene scene = new Scene(root, 400, 400);
            //scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
            primaryStage.setScene(scene);
            primaryStage.show();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        launch(args);
    }
}

and file css :

.table-view{
    -fx-background-color: black;
}

.spreadsheet-cell.childCatValue:filled:selected ,
.spreadsheet-cell.childCatValue:filled:focused:selected,
.spreadsheet-cell.childCatValue:filled:focused:selected:hover {
    -fx-border-color: #8cb1ff;
}

On Monday, October 30, 2017 at 5:32:06 PM UTC, ettien koua wrote:
Ok

samir.ha...@gmail.com

unread,
Nov 3, 2017, 5:26:41 AM11/3/17
to ControlsFX
Hi,

Please use the formatting button available in Google group so that your code is well shown.

Regarding your issue, you are actually creating cells that you are not using. I highly suggest that you go through your code in order to clean it, you would have seen the issue directly.

So in your example, you are doing :

 for (int row = 0; row < 1; row++) {
Basically, a one iteration loop. This is useless because the variable row is not used. Remove it.

After, you are doing that :
 SpreadsheetCell  cell = SpreadsheetCellType.INTEGER.createCell(rowIndex, column, 1, 1, 1);
                        cell
.getStyleClass().add("childCatValue");
                        list2
.add(SpreadsheetCellType.INTEGER.createCell(rowIndex, column, 1, 1, 1));

So you are creating a cell, and you are adding in list2 another cell that you create! Do you see the mistake?
So what you need to do is :
SpreadsheetCell  cell = SpreadsheetCellType.INTEGER.createCell(rowIndex, column, 1, 1, 1);
                        cell
.getStyleClass().add("childCatValue");

                        list2
.add(cell);

With that solution, you will have the border of the cell colored when selected. But if you only select one cell, you will not see it. Why? Because I add a black rectangle over the cells to show the selection just like Excel do. So either deactivate that rectangle if you don't want it, like that :
GridBase grid = new GridBase(rowCount, columnCount);

            grid
.setDisplaySelection(false);


Or simply override the color of that rectangle, for example :

.selection-rectangle{
   
-fx-fill : transparent;
   
-fx-stroke : red;
   
-fx-stroke-width : 2;
}

Regards,

ettien koua

unread,
Nov 4, 2017, 11:30:30 AM11/4/17
to ControlsFX
Thank you for all these recommendations.
Reply all
Reply to author
Forward
0 new messages