Java Jlabel/jbutton:在某些系统上,我得到了“ ...” (一个省略号),在某些系统上,我没有。我如何强制禁用省略号?
在大多数系统上,我的jlabel中的内容都很好。它的居住在某种程度上,它应该总是足够大以显示其内容文本,因为我基本上是这样做的:但是,
label.setText(text);
label.setFont(new Font(fontName, 0, 12));
int width = label.getFontMetrics(label.getFont()).stringWidth(text);
int height = 21; // this should always be enough
label.setBounds(new Rectangle(x, y, width, height));
在某些系统上(不是我自己的系统,所以我真的不能轻松调试它),它剪切了文本并显示“” ...“ 在最后。
您可以看到完整的代码您可以看到示例 。
我也有一些类似的案例。
我该如何强迫摇摆不这样做? (即使认为组件太小。)
摇摆到底在哪里处理这个?我浏览了jbutton
和一些相关类的代码,但我并没有真正找到剪切文本并添加省略号的代码。
On most systems, the content in my JLabel just shows fine. It is also resided in a way that it should be always big enough to show its content text because I basically do this:
label.setText(text);
label.setFont(new Font(fontName, 0, 12));
int width = label.getFontMetrics(label.getFont()).stringWidth(text);
int height = 21; // this should always be enough
label.setBounds(new Rectangle(x, y, width, height));
But on some systems (not my own so I cannot really debug it that easy), it cuts the text and shows "..." at the end.
You can see the full code here and you can see the example here (Abbildungen_Bijektiv_X3).
I also have some similar case for JButton.
How can I force Swing to not do that? (Even if it thinks that the component is too small.)
Where exactly does Swing handle this? I browsed through the code of JButton
and some related classes but I didn't really found the code where it cuts the text and adds the ellipsis.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不需要设置标签的界限。
那是布局经理的工作。学习使用布局经理,您将不会有这个问题。
编辑:
布局经理使用:
There should be no need to set the bounds of the label.
That is the job of a layout manager. Learn to use layout managers and you won't have this problem.
Edit:
Layout managers use:
我现在正在这样做(对于按钮,但您可以以类似的方式进行其他控件):
I am doing this now (for buttons but you could do it in a similar way for other controls):
您可以使用跨平台的外观和感觉(就像Nimbus一样)来停止这种情况
You could use a cross platform look and feel (Like Nimbus) to stop this occuring