删除三个点“...”来自 JButton?
嘿,我正在创建一个计算器程序,有一些小按钮,我希望其中一个按钮上有“Ans”,但是每当我使 JButton 小于 50、50 时,它就会显示三个点。 “...”,如何删除这些点并显示给定的正常文本?
Hey, I am creating a calculator program, with some small buttons, I want one of the buttons to have "Ans" on them, but whenever I make the JButton smaller then 50, 50, it will show three dots. "...", how can I remove these dots and show the normal text given?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
可能是因为你的按钮边距太大。
试试这个:
您还可以关闭边框:
Probably this because margin of your button is too big.
Try this:
You can also turn off border:
不要设置按钮的首选大小。使用按钮的首选大小并让布局管理器布局组件。首选尺寸可确保所有文本都能在不同的外观和感觉上正确显示。
Don't set the preferred size of the button. Use the preferred size of the button and let the layout manager layout the components. The preferred size ensures all the text will be displayed properly on different Look and Feels.
此代码试图解释为什么布局和首选尺寸如此重要。重要的部分在于输入/输出。
TestGuiSize.java
输入/输出
运行时参数只是运行之间差异的冰山一角,这些差异可能会影响应用程序的 GUI 代码。布局旨在处理此类差异。
This code attempts to explain why layouts and preferred sizes are so important. The important part lies in the input/output.
TestGuiSize.java
Input/output
Run-time parameters are just the tip of the iceberg of the differences between runs that might sink an application's GUI code. Layouts are designed to handle such differences.
您可以更改按钮上的字体大小。请参阅以下链接:
设置字体大小
增加字体大小(可以轻松更改为减小字体大小)
You could change the size of the font on the button. See these links:
Setting font size
Increasing font size (Can be easily changed to decrease font size)
使用
setMargin(Insets m)
调整 JButton 边框和标签之间的间距。默认值为(2, 14, 2, 14)
。为了最大化标签的可用空间(并完全删除点),您可以使用类似的东西Use
setMargin(Insets m)
to adjust the space between the JButton border and the label. The default is(2, 14, 2, 14)
. To maximize the space available for the label (and to remove the dots completely) you can use something like