javaswingloopsawtscrollpane

Java Swing / AWT - Best way to create a scrollpane section?


I'm creating a small social network for my programming class in Java Swing and AWT. I'm trying to create a ScrollPane that can contain posts from users. If the posts go out of the window, i want to be able to scroll through the posts (see image attached). What would be the best approach? Do i need to use a scrollpane, Jtable, JSlider? enter image description here On the image i have a pane on the left that works as a menu. I also have a pane on the right, which is where i want the posts (example image was made in Photoshop). The posts is being created by a loop.

I haven't included any code, since I'm just asking for the best approach.

Thanks


Solution

  • For this specific approach I suggest this:

    Use CardLayout for the right section, that changes based on which button you click on the left section.

    The left one would be a BoxLayout with vertical alignment.

    For each of the panels on the CardLayout, you add a JScrollPane so they are all independent from each other.

    And for the main panel I'd suggest a GridLayout so you can have both panes equally spaced.