Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within JavaFX
Search Coderanch
Advance search
Google search
Register / Login
Win a copy of
TDD for a Shopping Website LiveProject
this week in the
Testing
forum!
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Paul Clapham
Ron McLeod
Jeanne Boyarsky
Tim Cooke
Sheriffs:
Liutauras Vilda
paul wheaton
Henry Wong
Saloon Keepers:
Tim Moores
Tim Holloway
Stephan van Hulst
Carey Brown
Frits Walraven
Bartenders:
Piet Souris
Himai Minh
Forum:
JavaFX
why is the button not showing?
wesley johnsen
Greenhorn
Posts: 13
posted 5 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hello,
I'am making a gridpane with labels, textfields and 1 button.
But the button is not showing.
How can I fix this?
Can someone help me?
thanks in advance
public class App extends Application { @Override public void start(Stage primaryStage) { GridPane grid = new GridPane(); grid.setAlignment(Pos.CENTER); grid.setHgap(10); grid.setVgap(10); grid.setPadding(new Insets(25, 25, 25, 25)); Text scenetitle = new Text("app"); scenetitle.setFont(Font.font("Tahoma", FontWeight.NORMAL, 20)); grid.add(scenetitle, 0, 0, 2, 1); Label aantalBeesten = new Label("Count 1:"); grid.add(aantalBeesten, 0, 1); TextField TextFieldAantalBeesten = new TextField(); grid.add(TextFieldAantalBeesten, 1, 1); Label aantalPlanten = new Label("Count 2:"); grid.add(aantalPlanten, 0, 2); TextField TextFieldAantalPlanten = new TextField(); grid.add(TextFieldAantalPlanten, 1, 2); Label aantalObstakels = new Label("Count 3:"); grid.add(aantalObstakels, 0, 3); TextField TextFieldAantalObstakels = new TextField(); grid.add(TextFieldAantalObstakels, 1, 3); Button btn = new Button(); btn.setText("Say 'Hello World'"); HBox hbBtn = new HBox(10); hbBtn.setAlignment(Pos.BOTTOM_RIGHT); btn.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { System.out.println("Hello World!"); } }); StackPane root = new StackPane(); root.getChildren().add(btn); primaryStage.setScene(new Scene(grid, 500, 500)); primaryStage.setTitle("app"); primaryStage.show(); } /** * @param args the command line arguments */ public static void main(String[] args) { launch(args); } }
Norman Radder
Ranch Hand
Posts: 146
4
posted 5 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I don't know JavaFX but it looks to me like the components in root are not being added to the GUI that is being shown. The following change Scene will show the button, but not what is in grid.
StackPane root = new StackPane(); root.getChildren().add(btn); primaryStage.setScene(new Scene(root/*grid*/, 500, 500));
Norman Radder
Ranch Hand
Posts: 146
4
posted 5 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
What about adding the button to grid?
Don't MAKE me come back there with this tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Adding CSS produces error
Integration of javafx form to swing JOptionPane
no output
JavaFx internationalization
Implement drag and drop into a ListView that has custom CellFactory
More...