• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Making GUI for programs

 
Ranch Hand
Posts: 52
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello people,

im fairly new to java and have written a few small programs like BMI and simple calculator
was just wondering what the best way to make a gui was, i have read a few articles that have conflicting reports.
should i use swing or javafx...if javafx,should i use scenebuilder? or is there something better,if scenebuilder which version?

i hope somebody here can answer my questions,thanks!


 
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch!

I can definitely say, if you use JavaFX, use Scene Builder.  But the bigger question about Swing vs JavaFX is more difficult.  Swing is the old stand-by and is used in a lot of older code and some newer code.  JavaFX is newer, but no one knows how well it will be accepted.  Current coders haven't rushed to use JavaFX and even Oracle does not release a Scene Builder executable any more.

Still, I prefer JavaFX.  But that's just me.  I think the faster bet is to learn both.

Code Ranch has dedicated forums for both Swing and JavaFX.
 
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

I personally am neutral about FX versus Swing. In theory FX is going to take over all GUI work, but that doesn't seem to have happened. It probably doesn't matter much which you learn. But don't use Scene Builder or similar until you are much more experienced. I disagree with Knute; you need to learn the low‑level code and that means coding by hand.
 
warren brandt
Ranch Hand
Posts: 52
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for that
 
Rancher
Posts: 1093
29
Netbeans IDE Oracle MySQL Database Tomcat Server C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Warren,

I started in Java in 1999 and things were very different back in that day than it is today, but much is still true for good practice.  Here is my take on Java and GUI development: If you choose to use a tool to develop your GUI, FX or SWING or anything else, you run into one big problem. The GUI building apps are limited and sometimes they want to do one thing or they have implemented something a certain way, and you need to do it a different way for your application. If you cannot manually develop GUI"s, then you are not going to be able to fix the auto-coded GUI when it comes time that you need to do so.

I have literally seen this dozens of times in various development environments, including Java, and it is not a pretty sight: you have a complex GUI that has been auto-coded and it doesn't quite do what you need, so you get into the auto-code and fix it.  That breaks the auto-coder's ability to maintain the code, now you are on your own maintaining and modifying the existing auto-coded GUI. If you only knew enough to make the little change are in a world of hurt, or if you don't know enough to be able to make the change, then you are in a world of hurt also.

If you don't lean how to do the GUI coding for yourself, then feel free to use the auto-coder, you're going to get to a place like I described where you're between a rock and a very hard place. I've seen major projects stop because the team needed a GUI to do something that the auto-coder wouldn't do, and nobody had the ability to modify the code base generated by the auto-coder.

Now my personal preference: I like SWING, and that is just a personal preference. JavaFX is just as vaild of choice at this point. So try each, see what you like and follow that.  Keep an eye on the industry and see what winds out one technology usually comes to a point of dominance.

Les
 
Ranch Hand
Posts: 51
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use swing but get ready to hard work. Learn swing layouts first. Because I still do not know them well
 
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Note that JavaFX was written with the idea that it's GUI would be defined via XML, similar to the way an Android app is often defined.
Consequently there is (in that case) no auto-generation of code in the way that the Swing GUI builders do it.
There is XML defined wiring.
 
warren brandt
Ranch Hand
Posts: 52
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have decided to go for javaFX also read that you can customise the look with css...that sounds cool

just a last question

does code from javaFX run inside your program along with the background stuff?
or should you have a class called UserInterface that has methods to draw buttons etc

i will watch a few videos and see how it strings together

thanks for all the replies
 
Campbell Ritchie
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

warren brandt wrote:. . . does code from javaFX run inside your program along with the background stuff? . . .

Not sure I understand that question I am afraid. Please explain a bit more.

thanks for all the replies

That's a pleasure
 
Knute Snortum
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Start here for some good tutorials from Oracle:

http://docs.oracle.com/javase/8/javase-clienttechnologies.htm
 
warren brandt
Ranch Hand
Posts: 52
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks knute will start reading

campbell what i meant was:
does GUI swingFX code just go along side your regular program code,or is it better kept in its own class,then methods called etc
does this still not make sense?...what im asking
 
Campbell Ritchie
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Keep the GUI code and the business code in different classes.
 
warren brandt
Ranch Hand
Posts: 52
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok thanks will do,one last question.

would you code and get everything working on the console first and then create the GUI
or would you add the GUI as you going along,what do you think is the best approach?

 
Campbell Ritchie
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes; that's what I meant. Sorry for not being clear.
 
warren brandt
Ranch Hand
Posts: 52
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry now im not clear

code and get everything working on the console first then create the GUI? is this what you meant?
 
Knute Snortum
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is a tricky question.  I think the standard answer would be, "Code it all as a command line programs, then add GUI."  But I find that GUI programs are structured differently than command line programs.

I have a project called ScrabbleWords on my GitHub account (probably a trademark violation, but I digress.)  I first wrote it in Perl as a command line program.  Then I wrote it in Java as a JavaFX program.  It's true that Perl and Java are not similar, but beyond that, the projects are structured very differently.

It's true that some low-level classes came only came over the same (I use a Permuter and a Sublister) but that's about all.
 
Greenhorn
Posts: 10
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

warren brandt wrote:sorry now im not clear

code and get everything working on the console first then create the GUI? is this what you meant?



The general consensus among good programmers is learn to program your GUI manually. No matter which one you pick Swing or FX you need to hand code your applications. The IDE magic tools that give you a visual way to design your GUI will ultimately come back to bite you in the butt. You'll eventually run into a problem that requires you have a knowledge of the underlying GUI code to solve.

I think what the others are trying to say is keep your GUI and App code in separate files. I do this where possible.

For my personal pick I like FX but be warned the tables in JavaFX are very limited and can be tricky to program. If your application is going to have lots of tables with advance options then I'd suggest classic Swing.
 
Campbell Ritchie
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Agree with Christopher Sarama.

If you hit the rocks with tables, you can always embed a Swing JTable inside an FX application.
 
Knute Snortum
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just a note that SceneBuilder, the the layout program for JavaFX, produces XML files (specifically FXML), not code.  And the program follows closely what you would have to do if you coded by hand.  I can imagine laying out a complex GUI in SceneBuilder and then easily translating it to programming code.  Looking at the FXML can give you clues about how to code the GUI.

I've built application with JavaFX by hand and using FXML files.  The latter do have some problems, but the utility of SceneBuilder still stands.
 
Ranch Hand
Posts: 85
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
with javafx you can port your GUI applacation to run on  android with little to no code modification.  With swing  as your GUI you cannot port your app to android at all.  Javafx is  the GUI tool kit to learn and use.
 
Knute Snortum
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe the same can be said for web apps, although I have never tried it.
 
Aaaaaand ... we're on the march. Stylin. Get with it tiny ad.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic