用于多个标签的 JScrollPane
我正在开发一个具有流程布局的程序,里面有一组标签,因为标签太多,所以它们不会全部显示。无论如何,是否要添加一个滚动窗格来水平滚动所有这些标签?
JPanel mainpanel = new JPanel();
mainpanel.setLayout(new BoxLayout(mainpanel, BoxLayout.X_AXIS));
pane.add(mainpanel, BorderLayout.NORTH);
JPanel rightpanel = new JPanel();
rightpanel.setLayout(new FlowLayout());
for (int i = 0; i < 100; i++)
{
rightpanel.add(new JLabel("Label " + i));
}
mainpanel.add(new JLabel("Left label"));
mainpanel.add(new JScrollPane(rightpanel));
I am working on a program that has a flow layout, inside are a set of labels and because there are so many they do not all display. Is there anyway to add a scroll pane to scroll through all of these labels horizontally?
JPanel mainpanel = new JPanel();
mainpanel.setLayout(new BoxLayout(mainpanel, BoxLayout.X_AXIS));
pane.add(mainpanel, BorderLayout.NORTH);
JPanel rightpanel = new JPanel();
rightpanel.setLayout(new FlowLayout());
for (int i = 0; i < 100; i++)
{
rightpanel.add(new JLabel("Label " + i));
}
mainpanel.add(new JLabel("Left label"));
mainpanel.add(new JScrollPane(rightpanel));
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我建议不要使用 JList 或 JTable 具有一个
Column
或Row(取决于或方向),
JList
或JTable
中的对象默认为JLabel/JComponent
I'd suggest ot use JList or JTable with one
Column
orRow
(depends or direction), Object in theJList
orJTable
isJLabel/JComponent
by default不确定您的问题到底是什么,因为您已经知道需要使用
JScrollPane
。怎么样:Not sure what your question really is, since you already know you need to use a
JScrollPane
. How about: