Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to add content to a PopupControl in JavaFX 2.2.6?
    primarykey
    data
    text
    <p>I want to implement a simple popup control, which should be styleable with CSS. It's all working fine the only question is how to add content (a Node in JavaFX) to it?</p> <p>The <code>PopupWindow.getContent()</code> method is deprecated in JavaFX 2.2.6 and not working with CSS, I am able to see the content but the CSS-selector will not work then.</p> <p>So what is the best solution to add content myself, should I implement my own Skin class for that purpose or is there a simple way to just make it work?</p> <p>I have prepared a simple use case:</p> <pre><code>import javafx.scene.control.Label; import javafx.scene.control.PopupControl; import javafx.scene.layout.StackPane; import javafx.scene.shape.Rectangle; public class PopupTest extends PopupControl { public PopupTest() { getStyleClass().add("popup"); // not working!? StackPane pane = new StackPane(); pane.getStyleClass().add("pane"); Rectangle rectangle = new Rectangle(250, 250); rectangle.getStyleClass().add("rect"); Label text = new Label("popup test"); text.getStyleClass().add("text"); pane.getChildren().addAll(rectangle, text); // how to display to pane when the popup is shown? getContent().addAll(pane); } } </code></pre> <p>For completeness here are my MainApplication and CSS file:</p> <pre><code>import javafx.application.Application; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.stage.Stage; public class MainApplication extends Application { @Override public void start(Stage stage) throws Exception { Group root = new Group(); final Scene scene = new Scene(root); scene.getStylesheets().add(MainApplication.class.getResource("style.css").toExternalForm()); final Button button = new Button("show popup"); button.setOnAction(new EventHandler&lt;ActionEvent&gt;() { @Override public void handle(ActionEvent event) { PopupTest popup = new PopupTest(); popup.show(scene.getWindow()); } }); root.getChildren().add(button); stage.setScene(scene); stage.show(); } public static void main(String[] args) { launch(args); } } </code></pre> <p>style.css:</p> <pre><code>.popup { -fx-font-size: 24px; } .popup .rect { -fx-fill: green; } .popup .text { -fx-text-fill: white; -fx-font-weight: bold; } </code></pre> <p>The ".popup" selector is not working here, if I set it to the "pane" it will style the popup window so the css is correct: <code>pane.getStyleClass().add("popup"); // working with this "fix"</code>.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload