gpt4 book ai didi

java - 文本完全展开后的 SWT 水平线

转载 作者:行者123 更新时间:2023-11-30 08:25:23 27 4
gpt4 key购买 nike

我正在尝试在 SWT 的文本字段中显示历史记录。

历史会生成一个新的 shell,它有两个 Composites。第一个显示标题部分,其中包含标签“历史”和下方的水平线。第二个是显示实际数据的页 footer 分。这可行,但水平线不会在整个可用水平空间(即:直到复合“结束”)扩展(即:“填充”)。

               public void mouseDown(final MouseEvent e) {
findSegmentText.setText("");
if(0 == lastSegmentIds.size()) return;
if(disableToolTipsButton.getSelection()) return; // context help is not desired

if(null != popupShell) popupShell.dispose();

popupShell = new Shell(Display.getDefault(), SWT.BORDER | SWT.ON_TOP | SWT.MODELESS);
//popupShell.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
popupShell.setLayout(createNoMarginLayout(1, false));

/* Header */
compositeSearchSegments1 = new Composite(popupShell, SWT.NONE);
compositeSearchSegments1.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
compositeSearchSegments1.setLayout(createNoMarginLayout(1, false));


/* Footer */
compositeSearchSegments2 = new Composite(popupShell, SWT.NONE);
compositeSearchSegments2.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
compositeSearchSegments2.setLayout(createNoMarginLayout(2, false));

Label history = new Label(compositeSearchSegments1, SWT.NONE);
history.setText("History");

Label line1 = new Label(compositeSearchSegments1, SWT.SEPARATOR | SWT.SHADOW_OUT | SWT.HORIZONTAL);

for(int i = lastSegmentIds.size()-1 ; i>=0;i--) { // iterate backwards, higher indexes have newer selected links

final String lastSegmentId = lastSegmentIds.get(i);


l.setText(lastSegmentId);
Button b = new Button(compositeSearchSegments2, SWT.NONE);

b.setVisible(true);
b.setText(">>");
b.setSize(10,10);


b.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
findSegmentText.setText(lastSegmentId);
searchAndDisplayLink(Long.decode(findSegmentText.getText()));
}
});
}

Point point = optionsComposite.toDisplay(e.x + optionsComposite.getBounds().x +findSegmentText.getLocation().x, e.y + optionsComposite.getBounds().y+findSegmentText.getLocation().y );
popupShell.setLocation(point.x-125, point.y-10);
popupShell.pack();
popupShell.open();
findSegmentText.setFocus();

}

产生结果: enter image description here

我想扩展该行以填充可用的水平空间。我应该怎么办?谢谢。

最佳答案

因为您使用的是 GridLayout,所以将 GridData 添加到分隔符 Label 就可以了:

public static void main(String[] args)
{
Display display = new Display();
Shell shell = new Shell(display);
shell.setText("StackOverflow");
shell.setLayout(new GridLayout(1, false));

Label first = new Label(shell, SWT.NONE);
first.setText("short");

Label separator = new Label(shell, SWT.SEPARATOR | SWT.SHADOW_OUT | SWT.HORIZONTAL);
separator.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));

Label second = new Label(shell, SWT.NONE);
second.setText("looooooooooooooooooooooooooooooooooooong");

shell.pack();
shell.open();

while (!shell.isDisposed())
{
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}

看起来像这样:

enter image description here

关于java - 文本完全展开后的 SWT 水平线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22219978/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com