Popover of a default button inherits "default" styling from the button

Issue #824 new
Thorsten Kleidt
created an issue

The screenshot shows the misbehaviour. The "PopOver" button is the default. OnAction shows the popover with various controls that obviously adopt the style of the default button.

PopOverTest.PNG

public class PopoverDemo extends Application {

    @Override
    public void start(final Stage stage) throws Exception {
        final VBox container = new VBox();
        container.setSpacing(5.0);

        final Scene scene = new Scene(container, Color.DARKGRAY);
        UI.setStyle(scene);

        final VBox popoverContent = new VBox(5.0);
        popoverContent.setPadding(new Insets(5.0));

        final PopOver popOver = new PopOver(popoverContent);
        popOver.setAutoHide(true);
        popOver.setCloseButtonEnabled(true);

        final Label popoverTitle = new Label("TEST");
        final TextField popoverTextfield = new TextField("Popover");

        final TableView<String> popoverTableView = new TableView<>();
        final TableColumn<String, String> firstCol = new TableColumn<>("Col 1");
        final TableColumn<String, String> secondCol = new TableColumn<>("Col 2");
        final TableColumn<String, String> thirdCol = new TableColumn<>("Col 3");

        popoverTableView.getColumns().addAll(firstCol, secondCol, thirdCol);

        final Button btnPopoverClose = new Button("Close");
        btnPopoverClose.setOnAction(act -> popOver.hide());
        popoverContent.getChildren().addAll(popoverTitle, popoverTextfield, popoverTableView, btnPopoverClose);

        final Button btn = new Button("PopOver");
        final Button btnDummy = new Button("Dummy");
        btn.setDefaultButton(true);
        btn.setOnAction(act -> popOver.show(btn));

        container.getChildren().addAll(btn, btnDummy);

        stage.setTitle(getClass().getName());
        stage.setScene(scene);
        stage.setWidth(300);
        stage.setHeight(300);
        stage.show();

    }

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

}

Comments (6)

  1. Lukáš Brchl

    Hi all, I am having similiar issue with PopOver and TableView. The PopOver inherits TableRow focused style and changes all it elements. I have been struggling with it a month already and I cannot find any solution. I found, that when I set the focusTraversable property of TableView to false, the style is not inherited (added two screens). Unfortunately this quickfix with focusTraversable cannot be used in my case.

    Any thoughts on what is going on there? Adding easy sample app, so anyone can quickly run it and test it out.

    Screens:

    1) focusTraversable = false

    1.jpg

    2) focusTraversable = true

    2.jpg

    Code:

    public class Controller implements Initializable {
    
        @FXML private AnchorPane anchorPane;
        @FXML private TableView<String> tableView;
        @FXML private TableColumn<String, String> firstColumn;
    
        private final PopOver popOver = new PopOver();
        private final ObservableList itemsList = FXCollections.observableArrayList("Hello", "this", "is", "test");
    
        public Controller() {}
    
        @Override public void initialize(URL location, ResourceBundle resources) {
            firstColumn.setCellFactory(createCellFactory());
            tableView.setItems(itemsList);
            tableView.setFocusTraversable(false);
            popOver.setContentNode(new VBox(new Label("Label"), new Separator(), new Label("Second label"), new TextField(), new TextField()));
        }
    
        public Callback<TableColumn<String, String>, TableCell<String, String>> createCellFactory() {
            return new Callback<TableColumn<String, String>, TableCell<String, String>>() {
                @Override public TableCell<String, String> call(TableColumn<String, String> param) {
                    param.setCellValueFactory(p -> new ReadOnlyStringWrapper(p.getValue()));
                    return new TableCell<String, String>() {
                        @Override
                        protected void updateItem(String item, boolean empty) {
                            super.updateItem(item, empty);
                            if (!empty) {
                                setGraphic(new Label(item));
                                this.setOnMouseClicked(event -> {
                                    if (!popOver.isShowing())
                                        popOver.show(this);
                                });
                            } else setGraphic(null);
                        }
                    };
                }
            };
        }
    }
    
    <?xml version="1.0" encoding="UTF-8"?>
    
    <?import javafx.scene.control.TableColumn?>
    <?import javafx.scene.control.TableView?>
    <?import javafx.scene.layout.AnchorPane?>
    
    <AnchorPane fx:id="anchorPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.141" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.Controller">
       <children>
          <TableView fx:id="tableView">
            <columns>
              <TableColumn fx:id="firstColumn" prefWidth="247.0" text="C1" />
            </columns>
          </TableView>
       </children>
    </AnchorPane>
    
    public class Main extends Application {
    
        @Override
        public void start(Stage primaryStage) throws Exception {
            Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
            primaryStage.setScene(new Scene(root));
            primaryStage.show();
        }
    
        public static void main(String[] args) {
            launch(args);
        }
    }
    
  2. Log in to comment