Hack Forums
[Java] JavaFX GUI - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [Java] JavaFX GUI (/showthread.php?tid=5875994)



JavaFX GUI - Consulting Detective - Aug 20, 2018

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();

 
   }
} 



RE: JavaFX GUI - Dostoevsky - Aug 20, 2018

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).


RE: JavaFX GUI - HFDone - Aug 20, 2018

😉 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())); 



RE: JavaFX GUI - GenericSkid - Aug 21, 2018

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.


RE: JavaFX GUI - +Haze - Aug 29, 2018

It's always best to GUI builders like the scene builder unless you need to create controls dynamically.