java - 水平滚动条在 CTabItem 内的复合下不起作用

标签 java swt eclipse-rcp composite

我有 CtabItem,其中有一个 Composite 小部件。 然后,我在里面添加了一些组件。 代码是这样的 -

Composite composite = new Composite(tabFolder, SWT.H_SCROLL);

    tabItem.setControl(composite);


    Label lblName = new Label(composite, SWT.NONE);
    lblName.setBounds(10, 28, 55, 15);
    lblName.setText("Name");

    textName = new StyledText(composite, SWT.BORDER);
    String myText = tree.getSelection()[0].getText();
    textName.setText(myText);
    Point textNamesize = textName.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    textName.setBounds(76, 28, textNamesize.x, 21);

    Label lblPath = new Label(composite, SWT.NONE);
    lblPath.setBounds(10, 83, 55, 15);
    lblPath.setText("Path");

    textPath = new StyledText(composite, SWT.READ_ONLY);
    textPath.setBackground(new Color(d, 240, 240, 240));


    Button saveButton = new Button(composite, SWT.NONE);
    saveButton.setBounds(456, 134, 75, 25);
    saveButton.setText("Save");


    Button cancelButton = new Button(composite, SWT.NONE);
    cancelButton.setBounds(548, 134, 75, 25);
    cancelButton.setText("Cancel");

但是,当我显示选项卡时,滚动条存在,但是,当我滚动复合时,滚动条移动,但滚动条另一侧的元素没有显示 知道为什么它不起作用吗?

谢谢!

最佳答案

来自 GGrec 的 answer我为你创建了片段。 我将 ScrolledComposite 与 GridLayout 一起使用。希望它能让您的任务更轻松。

 final ScrolledComposite scrolledComposite = new ScrolledComposite(parent, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
            scrolledComposite.setExpandHorizontal(true);
            scrolledComposite.setExpandVertical(true);

            final Composite composite_parent = new Composite(scrolledComposite, SWT.NONE);
            composite_parent.setLayout(new GridLayout(3, false));
            scrolledComposite.setContent(composite_parent);
            scrolledComposite.setSize(composite_parent.computeSize(SWT.DEFAULT, SWT.DEFAULT));

            final Composite composite_child = new Composite(composite_parent, SWT.NONE);
            composite_child.setLayout(new GridLayout(2, false));

            final Label lblDefault1 = new Label(composite_child, SWT.NONE);
            lblDefault1.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
            lblDefault1.setText("Name");

            final StyledText textStyled = new StyledText(composite_child, SWT.NONE);
            textStyled.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1));

            Label lblNewLabel_1 = new Label(composite_child, SWT.NONE);
            lblNewLabel_1.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
            lblNewLabel_1.setText("Path");

            text = new Text(composite_child, SWT.BORDER);
            text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

            scrolledComposite.setMinSize(composite_parent.computeSize(SWT.DEFAULT, SWT.DEFAULT));

关于java - 水平滚动条在 CTabItem 内的复合下不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32862239/

相关文章:

java - 如何使 Hibernate Spring Repository 返回 HashMap

java - 在 Swing 应用程序中运行 SWT 组件

java - SWT 程序.启动邮件客户端

java - 获取 Eclipse RCP 中的 Activity 插件列表

java - Eclipse PDE 中的日志记录策略

java - 如何查找 ASTNode 的所有子节点(子节点和子节点的子节点)

java - 字符串的 HashSet 占用太多内存,建议...?

java - Swing 模糊拖动图像

java容器对象交换数组方法

java - 如何在不给出静态列宽的情况下创建具有多列的 Java SWT 表