Hello.
I usually don't ask you guys for help but this time I got frustrated because I wasted too much time already and my project due is getting closer and closer.
I have this project to design a small app for online shipping. The problem is I don't know which layouts to use. Grid, Box and Border are not working for me. ( I'm probably doing something wrong). Lets say I want to setSize of my JFrame (which is BorderLayout) to be 500 px width, and all the content ( JPanels with items picture price etc ) to be always the same size, aligned in one row from left to right and if I add more and more JPanels, it will not squeeze them together or float them down to second row but use a scroll bar instead.
Pretty much I want to have a horizontal content pane with scroll bar, one row only, every content not resizable (not affected by LayoutManager).
Thank you guys for help!
>>53847179
What's stopping you from using JavaFX and Scene Builder?
It's superior aesthetically as well.
I'm a beginner, don't know much about GUIs
>>53847278
>Pretty much I want to have a horizontal content pane with scroll bar, one row only, every content not resizable (not affected by LayoutManager).
You literally just described FlowLayout. It arranges all of the components that you add horizontally to each other; they are set to their preferredSize() and don't resize with the panel.
What you want to do is add a ScrollPane. Set the content pane of the ScrollPane to your FlowLayout pane.
And just so you're aware: you CAN mix and match layouts. Once I realized that, everything got a ton easier.
I'm sorry but I'm still kinda lost. Could you post a simple code for it ? I know I sound like a noob but that's my first GUI project.
>>53847917
Here's your code
curl "https://www.google.com/search?q=flowlayout"
>>53847917JPanel flow = new JPanel(new FlowLayout());
JScrollPane scroller = new JScrollPane(flow);
frame.getContentPane().add(scroller);
Wow thanks, you helped a lot. ;)
OK let's try this. How do I force my FlowLayout to keep all my JPanels in one row? It's obviously checking the width of my JFrame and if 2 JPanels can't fit in JFrame it automatically moves one to the bottom. I want it to be independent and the only thing that changes during resizing my JFrame would be scrollbar.
>>53848013
Thank you kind sir !