+ 7
How can I make a GUI Programme in Java?
GUI programming?
12 Answers
+ 1
There are 3 packages you can use. awt, swing, javafx. javafx is the latest. If you need to develop GUI applications, then you have to learn about one of these.
+ 4
I mean I want to do it with java.Do you have any idea?
+ 3
I would appreciate if someone could tell me about JavaFX.
+ 2
If I mean java, Netbeans is one of the most used ide for java. In netbeans you can create GUIs in mode with graphical interface or with code directly
+ 2
For creating a Javafx application, you should first extend your main class to Application. Then you have to override start(). In your main funtion you write:
launch(args).
Now look at your start function:
It has got one argument, the Stage primaryStage. This is your base.
Then you write there:
Pane root = new Pane();
Scene scene = new Scene(pane, 1000, 500);
primaryStage.show();
root.setVisible(true);
If you did that, and run your code, an empty window pops up. Your first JavaFx Window!
Every object on the root pane such as Buttons, TextViews or ImageViews extend from Node. Those you can put on your GUI.
Example for adding a button:
Button button = new Button("The text");
button.setOnAction(event -> {
//do stuff
}
button.setLayoutX(10); //horizontal positioning
button.setLayoutY(10); //vertical pos.
root.getChildren().add(button);
+ 1
I advice you NetBeans
+ 1
Jonas Schroyer, can you please give me a good resource to learn javafx. ?
+ 1
Sachintha Sampath I really don't know how I learned JavaFX myself... I just followed the steps I described. To develop my GUI, I looked up single kinds of Nodes such as Listviews etc. I'd recommend to do it that way:)
+ 1
Thanks..!! I will try that. But I am still learning swing and awt. Is the coding similar in they both swing and javafx. ?
+ 1
Mmh, many Node's names are pretty self explaining, so looking them up is pretty easy. I didn't try Swing nor awt, so I can't compare them to JFX
+ 1
Use NetBeans and if you know swing in Java, generate project and start.
*You must know swing or other GUI programming "way"
0
I would not recommend to use WindowBuilder or such stuff. I mostly use only JavaFX without previews. It's pretty easy to work with after while.