简体   繁体   English

Java Swing / AWT - 创建滚动窗格部分的最佳方式?

[英]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.我正在为我的 Java Swing 和 AWT 编程课程创建一个小型社交网络。 I'm trying to create a ScrollPane that can contain posts from users.我正在尝试创建一个可以包含用户帖子的 ScrollPane。 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?我是否需要使用滚动窗格、Jtable、JSlider? 在此处输入图片说明 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).我在右边也有一个窗格,这是我想要帖子的地方(示例图像是在 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谢谢

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.CardLayout用于右侧部分,根据您在左侧部分上单击的按钮进行更改。

The left one would be aBoxLayout with vertical alignment.左边的将是一个垂直对齐的BoxLayout

For each of the panels on the CardLayout , you add a JScrollPane so they are all independent from each other.对于CardLayout上的每个面板,您添加一个JScrollPane以便它们彼此独立。

And for the main panel I'd suggest a GridLayout so you can have both panes equally spaced.对于主面板,我建议使用GridLayout这样您就可以让两个窗格等距。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM