Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Java 

JavaFX GUI

Quick question, when creating javafx GUIs, do you guys prefer fxml or raw java code?

I only started learning it, and I seem to favor just the java code. Though I know using fxml can segregate software functionality and software gui.
Maybe the only reason l don't like fxml is because I'm unfamiliar with it, I have never dealt with xml before. But I heard before that it has something to do with web development. I really need to google it lol.

What do you guys think?

P.S code below is my first javaFX app. So no hate :)

PHP Code

<?php 
import javafx
.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.FlowPane;
import javafx.stage.Stage;

public class 
MainProg extends Application {

 
   private static int x = 0;

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

 
   public void start(Stage mainStage){

 
       mainStage.setTitle("Software: Add 1");

 
       FlowPane myLayout = new FlowPane();
 
       Label myLabel = new Label("   " + x);
 
       Button myButton = new Button("Add 1");
 
       myButton.setOnAction(e -> {
 
           x++;
 
           myLabel.setText("   " + x);
 
       });

 
       myLayout.getChildren().addAll(myButton, myLabel);
 
       Scene myScene = new Scene(myLayout, 150, 75);
 
       mainStage.setScene(myScene);
 
       mainStage.show();

 
   }
} 
I mean, you're saying you prefer writing out UIs by hand after writing your first JavaFX application that consists of a label and a button component grouped into a flow-layout. You should play more with scene builder, saves a lot of time for most things. People often forget that you can create custom components and import them into scene builder to use your own components in a WYSIWIG manner (which is convenient).

Generally I find it best to make UIs rather modular so I can modify the UI using scene builder but utilise the custom component dynamically. E.g. populate a scroll pane with lots of custom components for displaying information about something.

Some would call me unconventional for generally favouring Java Swing over JavaFX in most instances though (I just did it for a long time before JavaFX was even a thing and seldom see the point in using JavaFX - or Java, nowadays, for that matter).
Dostoevsky(const Dostoevsky&) = delete;
[Image: T4BXHDP.png]
😉 use javax.swing
PHP Code

<?php 
JFrame frame 
= new JFrame();
frame.setTitle("Form");
frame.setBounds(100, 100, 300, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
frame.setVisible(true);
 
   
JLabel lbl 
= new JLabel("Label");
lbl.setBounds(130, 60, 90, 30);
frame.getContentPane().add(lbl);
 
       
JButton btn 
= new JButton("Button");
btn.setBounds(100, 110, 90, 30);
btn.setFocusPainted(false);
frame.getContentPane().add(btn);
btn.addActionListener(e -> System.out.println(lbl.getText())); 
[Image: bitcoin.png] Be Nice For Once 15hVUVz7xA4kazHdk2BuErENGCskVwjYXP
I too create my UI's through code. I tried using the WYSIWYG editor but I gave up half way though because I knew what I wanted and could make it in code faster than it would take me to learn the WYSIWYG editor.

(Aug 20, 2018 04:21 AM)Dostoevsky Wrote:  Some would call me unconventional for generally favouring Java Swing over JavaFX in most instances though

Its understandable though. Swing has been around for much longer and has been bundled with the JRE for a long time. JFX is being removed in future releases so you'll have to bundle it as a dependency yourself. Sucks for people like me with shitty internet speeds.
It's always best to GUI builders like the scene builder unless you need to create controls dynamically.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Java] by OBAMASELFFeb 8, 2019 03:13 AM 2 204 Feb 8, 2019 03:13 AM
Last Post: OBAMASELF
[Java] by TennoFeb 3, 2019 04:49 AM 4 300 Feb 3, 2019 04:49 AM
Last Post: Tenno
[Java] by +HazeJun 9, 2017 12:47 AM 61 8,270 Jun 9, 2017 12:47 AM
Last Post: +Haze