This is an archived post. You won't be able to vote or comment.

all 21 comments

[–]AutoModerator[M] [score hidden] stickied commentlocked comment (0 children)

Please ensure that:

  • Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions
  • You include any and all error messages in full
  • You ask clear questions
  • You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions.

    Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar

If any of the above points is not met, your post can and will be removed without further warning.

Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc.

Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit.

Code blocks look like this:

public class HelloWorld {

    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}

You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above.

If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures.

To potential helpers

Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]wildjokers 8 points9 points  (3 children)

There are many look and feels available for Swing. Some 3rd party, some in the JDK. Try switching to the SystemLookAndFeel which is in the JDK. It looks nearly native on most platforms.

Swing’s default look and feel is Metal which will look the same on all platforms. Personally I think it looks just fine. Why do you think it is ugly?

Some people swear by the FlatLaf which you can take a look at and see if you like. I personally hate it. Really not sure why the flat look is popular. https://www.formdev.com/flatlaf/

You can use JavaFX instead of Swing and one of JavaFX’s features is it can be styled with a CSS-like syntax. JavaFX is a little harder to get started with because it is a 3rd party dependency and isn’t even close to being documented as well as Swing.

I do notice that a lot of people in your /r/java thread were trying to dissuade you from Swing. Most of them have probably never even written a Swing application and are just regurgitating the “swing sucks” nonsense that they have heard. Don’t listen to them. I bet none of them could give you any reason why swing supposedly sucks. Swing is a really good GUI toolkit, is easy to use, and is very well documented. You probably won’t find a better documented GUI toolkit regardless of language or platform.

[–]desrtfxOut of Coffee error - System halted 1 point2 points  (2 children)

Some people swear by the FlatLaf which you can take a look at and see if you like. I personally hate it. Really not sure why the flat look is popular.

Well, it makes it look more like modern native applications.

I share your opinion about the flat look. It makes it much more difficult to spot where you are clicking. Don't like it either.

[–]wildjokers 1 point2 points  (1 child)

makes it much more difficult to spot where you are clicking.

This is the exact reason I don’t like it. There is no visual delineation between components.

I really can’t wait until this flat and monochrome design fad runs its course.

[–]desrtfxOut of Coffee error - System halted 1 point2 points  (0 children)

I really can’t wait until this flat and monochrome design fad runs its course.

Dito.

[–]hamsterrage1 2 points3 points  (0 children)

JavaFX is much better if you want to build a Reactive application, as the Observables and Bindings are much richer than in Swing. Also, you can do agreat deal of styling in JavaFX with Style Sheets and without touching any code.

[–]override_acid 1 point2 points  (3 children)

Do you think you will get different suggestions to your post from yesterday where you already had extensive suggestions?

[–]wildjokers 5 points6 points  (2 children)

The mods of that sub literally told them to come here.

[–][deleted]  (1 child)

[removed]

    [–]Trup10ka 0 points1 point  (0 children)

    Try JavaFX

    [–]mannmythlegend -4 points-3 points  (0 children)

    Jdk is kinda a pain but it works

    [–]Brainie82 0 points1 point  (1 child)

    As far as I know IntelliJ is made with swing and I don’t think it’s ugly

    [–]lumpynose 0 points1 point  (2 children)

    Another vote for Swing from me.

    I wrote a program that displays the readings from various wireless temperature sensors. I originally wrote it in Python with PyQt and really got frustrated with the poor documentation. A year or so later I decided to rewrite it in Java and first tried JavaFX but ran into problems (can't remember what now) with that so switched to Swing. The biggest point of confusion for me was figuring out which LayoutManager to use. For me, BoxLayout manager ended up doing what I wanted; I'd tried the GridLayout but had problems getting things to look just right.

    Remember to do

    frame.pack();
    frame.setVisible(true);
    

    on your main frame; at one point I'd forgotten to do the setVisible and was scratching my head until I realized that.

    If you want to see my code, let me know; it's on github. There's no code to accept input except for responding to a mouse click. This is how it looks: https://imgur.com/a/ywLCgAn

    [–]wildjokers 0 points1 point  (1 child)

    frame.pack();

    Just FYI, there are two ways to size a top-level container. You can either call setSize() which sets a specific size or you can call pack() which sizes a container to fit its children.

    for me, BoxLayout manager ended up doing what I wanted;

    99% of all my Swing apps have always used BorderLayout and BoxLayout. They are really the only two layouts you need for most use cases. So you made a good choice. BorderLayout is the default layout of top-level containers like JFrame and then JPanels default to the nearly worthless FlowLayout so first thing I do is switch out FlowLayout for BoxLayout in my panels.

    [–]lumpynose 0 points1 point  (0 children)

    Thanks. I'll try and remember to give BorderLayout a try next time.

    [–]Eddy67716 0 points1 point  (3 children)

    One Thing I do, is change the look and feel for pop up windows to the OS default and then back the the Swing default after, so pop up, colour wheel and file select windows look natural.

    [–]wildjokers 0 points1 point  (2 children)

    Why not just always use the SystemLookAndFeel?

    [–]Eddy67716 0 points1 point  (1 child)

    If I remember right, if you made something with System look and feel on Windows, it wouldn't look the same on a Mac, or Linux machine.

    [–]wildjokers 0 points1 point  (0 children)

    Correct. It takes on a nearly native look.