为什么我的组件没有包含在 Swing 的 FlowLayout 中? [英] Why aren't my components wrapping in Swing's FlowLayout?

查看:33
本文介绍了为什么我的组件没有包含在 Swing 的 FlowLayout 中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我的组件没有使用 FlowLayout 包裹在这个 JPanel 中?它们只是在屏幕外运行,并且仅部分可见.

Why aren't my components wrapping in this JPanel using FlowLayout? They simply run off screen and are only partially visible.

JPanel panel = new JPanel(new FlowLayout());
panel.add(new JLabel("TEST"));
// ... repeat adding JLabels until they go off screen when they SHOULD wrap
// to the next line...

这就是我的全部代码(除了添加和打包框架).我误解了 FlowLayout 吗?我是否必须在标签或面板上设置某种大小?

That's the entirety of my code (aside from adding and packing the frame). Am I misunderstanding FlowLayout? Do I have to set some sort of size on either: the labels or the panel?

推荐答案

那是因为 FlowLayout 没有.我知道,这很糟糕.

That's because FlowLayout doesn't. I know, it sucks.

但是,你可以看看 WrapLayout 这是这个问题的解决方案

But, you could take a look at WrapLayout which is a solution to this problem

这篇关于为什么我的组件没有包含在 Swing 的 FlowLayout 中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆