如题,我想通过按钮上的文本内容动态调整JButton的大小,以确保文本在多语言下完整显示。但我不知道如何获取JButton上文本的宽度.
JButton btn = new JButton("Sure");
预先感谢您的帮助。
最佳答案
I want to resize a JButton dynamicly by the Text Content on the button to make sure the Text is showing integrally under Multi-Language.But I don't know how to get the width of the Text on JButton.
您不需要明确地执行此操作,因为如果您正确使用布局管理器,它们会为您处理好。如果您在 GUI 呈现后将 JButton 添加到 GUI,则只需重新验证并重新绘制获取按钮的容器,布局管理器应该完成其余的工作。
请注意,如果此建议对您没有帮助,那么您可能需要告诉我们有关您的计划和问题的更多信息。
关于java - 如何在 Swing JButton 中获取文本内容像素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17736971/