0

I'm working on a GUI that has the following view when I compile the code: enter image description here

As you can see, this JFrame is made up with differents JPanels. The section 'All subjects' is a JPanel that has a FlowLayout so the panels inside it are near each other as they are being created. I want to add a scroll bar to this panel so the data inside it (yellow and green panels) are all along the same row.

Here's the output I want:

enter image description here

How can I create that scroll bar?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
user157629
  • 624
  • 4
  • 17
  • 1
    Give the all subjects JPanel a GridLayout(1, 0) (one row, variable columns), add it to a JScrollPane's viewport, and then add the JScrollPane to the GUI. For more specific help, you would want to create and post a [mre] post. Else this question is a duplicate. – Hovercraft Full Of Eels Mar 08 '20 at 14:04
  • @HovercraftFullOfEels Thanks, that was what I was looking for and it worked. – user157629 Mar 08 '20 at 14:12
  • You're welcome. Note that sometimes I have had to wrap the first GridLayout-using JPanel (here the all-subjects JPanel) in the LINE_START region of a GridLayout-using JPanel, and then add *that* JPanel to the scroll pane's viewport. This will prevent the first JPanel for expanding too much when first adding items to it. – Hovercraft Full Of Eels Mar 08 '20 at 14:19

0 Answers0