简体   繁体   English

JCheckBox:多行文本的垂直对齐

[英]JCheckBox: Vertical alignment for multi-line text

I have come across a slight visual issue in Java (swing) when using custom fonts with a JCheckBox. 当将自定义字体与JCheckBox一起使用时,我在Java中遇到了一个轻微的视觉问题(摆动)。 I have a JCheckBox with text spanning multiple lines. 我有一个JCheckBox,其文本跨越多行。 When using the default font, it looks fine. 使用默认字体时,看起来不错。 However, when I use a custom font (imported on-the-fly from a .ttf file), the vertical alignment seems to be slightly offset, making it look ugly. 但是,当我使用自定义字体(从.ttf文件动态导入)时,垂直对齐方式似乎略有偏移,从而使外观看起来很难看。 The text accompanying the checkbox should be slightly higher than it appears. 伴随复选框文本应该比它出现小幅上扬

Is there any way to tweak the vertical position of the checkbox its text label? 有什么办法可以调整复选框的垂直位置的文本标签? This happens when I use this code to align the checkbox at the top: checkbox.setVerticalTextPosition(SwingConstants.TOP) 当我使用以下代码在顶部对齐复选框时,会发生这种情况: checkbox.setVerticalTextPosition(SwingConstants.TOP)

在此处输入图片说明

Each platform specifies physical fonts to use for the defined logical Font families. 每个平台都指定用于定义的逻辑 Font系列的物理字体。 These fonts have well-defined metrics that are known to be compatible with the host platform. 这些字体具有定义明确的指标,已知与主机平台兼容。 Using an odd-lot font puts you at the mercy of the font's designer and the platform's implementation of font hints. 使用奇数字体使您不受字体设计者和平台字体提示实现的约束。 Instead, use the UIManager to derive the desired size and style before constructing the GUI, as shown here . 相反,使用UIManager构造GUI 之前 获得所需的大小和样式,如图所示这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM