Peter Penzov
Peter Penzov

Reputation: 1668

How to make TabPane borders green

I implemented drag and drop example from the JavaFX tutorial.

And I managed to add effect when I drag a tab over a target TabPane:

tabPane.setOnDragEntered(new EventHandler<DragEvent>() {
            @Override
            public void handle(DragEvent event) {
                /* the drag-and-drop gesture entered the target */
                /* show to the user that it is an actual gesture target */
                if (event.getGestureSource() != tabPane
                        && event.getDragboard().hasString()) {
                    tabPane.setCursor(Cursor.MOVE);


                    tabPane.setEffect(new Glow());
                }

                event.consume();
            }
        });

        tabPane.setOnDragExited(new EventHandler<DragEvent>() {
            @Override
            public void handle(DragEvent event) {
                /* mouse moved away, remove the graphical cues */
                tabPane.setCursor(Cursor.DEFAULT);

                tabPane.setEffect(null);

                event.consume();
            }
        });

But I would like to to make the borders of the target TabPane green instead of adding Glow effect. Is this possible?

Upvotes: 1

Views: 3510

Answers (2)

M2E67
M2E67

Reputation: 970

this work for me:

tabPane.setStyle("-fx-border-style:solid; -fx-padding: 1; -fx-background-color: green;");

or use other possible values for -fx-border-style attribute such as double,dashed , ...

Upvotes: 0

Nick Rippe
Nick Rippe

Reputation: 6465

You can set the style on the TabPane (set it to a blank string afterwards):

 tabPane.setStyle("-fx-padding: 1; -fx-background-color: green, -fx-control-inner-background; -fx-background-insets: 0, 1;");

OR if you want to be really cool, you could do it all in a CSS style sheet (and add the styleClass "dragTab" to all your Tab Panes when you start the drag (and remove when the drag ends). It eliminates two mouse listeners at least.

.dragTab:hover {
    -fx-padding: 1; 
    -fx-background-color: green, -fx-control-inner-background; 
    -fx-background-insets: 0, 1;
}

Upvotes: 3

Related Questions