Linux开发板显示字体右对齐,同时在Linux / Gnome中的SWT标签中右对齐和换行文本

简短回答:

使用StyledText而不是Label - 所有条件都相同。

详细解答:

关于这个“功能”,GTK中存在许多错误(120256是一个很好的切入点),其中大多数都标记为彼此重复,其中大多数都追溯到gtk + 2.4 / 2.6,其中一些标记为固定。然而,在2011年gtk2 + 2.22版本(针对Maverick Market),漏洞似乎非常有弹性。

阅读了这个错误报告之后,我在整个SWT源代码树中找到了wordwrap关键字,看起来Steve Northover男孩们使用StyledText Control比使用Label Control更好地解决了这个问题。

我重用了Favonius测试用例(很多Favonius ;-),这显然是好兆头。

import org.eclipse.swt.SWT;

import org.eclipse.swt.custom.StyledText;

import org.eclipse.swt.layout.GridData;

import org.eclipse.swt.layout.GridLayout;

import org.eclipse.swt.widgets.Display;

import org.eclipse.swt.widgets.Shell;

import org.eclipse.swt.widgets.Text;

public class RightAlign2

{

public static void main(String[] args)

{

Display display = new Display();

Shell shell = new Shell(display);

GridLayout layout = new GridLayout();

layout.numColumns = 2;

shell.setLayout(layout);

shell.setText("Alignment Test");

String[] labelTexts = new String[]{"label 1:","Another label:","Another label with wrapped text:"};

for (String labelText : labelTexts)

{

StyledText fieldText = new StyledText(shell, SWT.RIGHT |SWT.WRAP | SWT.BORDER );

fieldText.setText(labelText);

GridData labelGridData = new GridData(GridData.HORIZONTAL_ALIGN_END);

labelGridData.widthHint = 100;

fieldText.setLayoutData(labelGridData);

Text textField = new Text(shell, SWT.BORDER);

GridData textGridData = new GridData(GridData.FILL_HORIZONTAL);

textGridData.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING;

textGridData.widthHint = 248;

textField.setLayoutData(textGridData);

}

shell.pack();

shell.open();

while (!shell.isDisposed()) {

if (!display.readAndDispatch()) display.sleep();

}

display.dispose();

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值