我的SWT标签不会随着在组合框中选择新项目而更改文本吗?

时间:2019-02-11 17:07:36

标签: java label swt refresh

我当前使用的是绝对布局,我有一个标签,随着在组合框中选择一个新项目,该标签应该更改。我将其与网格布局一起使用,但这与其他功能,按钮和标签弄混了,我将如何我为我做这项工作。。。 这是我正在谈论的代码的一部分:

    Combo comboLevels = new Combo(shellAfterCasual, SWT.NONE);
    comboLevels.setBounds(10, 40, 91, 23);
    String[] item = new String[] { "Swedish 1", "Swedish 2", "Swedish 3" };
    comboLevels.setItems(new String[] {"Swedish 1", "Swedish 2", "Swedish 3"});
    comboLevels.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
             levelStr1 = comboLevels.getItem(comboLevels.getSelectionIndex());
            System.out.println("Selection: " + comboLevels.getItem(comboLevels.getSelectionIndex()));


            Label lblvarLvlLabel = new Label(shellAfterCasual, SWT.NONE);
            lblvarLvlLabel.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.BOLD | SWT.ITALIC));
            lblvarLvlLabel.setBackground(SWTResourceManager.getColor(SWT.COLOR_INFO_BACKGROUND));
            lblvarLvlLabel.setBounds(145, 5, 107, 27);
            lblvarLvlLabel.setText(comboLevels.getText());
            lblvarLvlLabel.getParent().layout();
            /*'''''''''''''.............'''''''''''''''''''''''''''''''''''''''''''*/
            System.out.println("XDDD;"+levelStr1);
        }
    });

1 个答案:

答案 0 :(得分:0)

我终于找到了解决方法,我在动作侦听器外部启动了标签,以使标签始终存在,但是当这样选择标签时,它会.setText和.updates:

Label lblvarLvlLabel = new Label(shellAfterCasual, SWT.NONE);
    lblvarLvlLabel.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.BOLD | SWT.ITALIC));
    lblvarLvlLabel.setBackground(SWTResourceManager.getColor(SWT.COLOR_INFO_BACKGROUND));
    lblvarLvlLabel.setBounds(145, 5, 107, 27);


    Combo comboLevels = new Combo(shellAfterCasual, SWT.NONE);
    comboLevels.setBounds(10, 40, 91, 23);
    String[] item = new String[] { "Swedish 1", "Swedish 2", "Swedish 3" };
    comboLevels.setItems(new String[] {"Swedish 1", "Swedish 2", "Swedish 3"});
    comboLevels.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
             levelStr1 = comboLevels.getItem(comboLevels.getSelectionIndex());
            System.out.println("Selection: " + comboLevels.getItem(comboLevels.getSelectionIndex()));
            lblvarLvlLabel.setText(comboLevels.getText());
            lblvarLvlLabel.getParent().layout();
            lblvarLvlLabel.redraw();
            lblvarLvlLabel.update();
        }
    });