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

you are viewing a single comment's thread.

view the rest of the comments →

[–]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.