简体   繁体   English

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

[英]My SWT label is not changing text with the selection of new item in combobox?

I am currently using absolute layout and I have a label which is supposed to change as a new item is selected in the combo box I made it work with grid layout but this messes with other functions, buttons and labels I have how would I make this work for me... anything would be appreciated.. this is the part of the code i am talking about: 我目前正在使用绝对布局,我有一个标签,随着在组合框中选择一个新项目,该标签应该更改。我将其与网格布局一起使用,但是这与其他功能,按钮和标签混淆了,我将如何制作此标签为我工作...一切都会感激的..这是我正在谈论的代码的一部分:

    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);
        }
    });

I finally found out how to do this i initiated the label outside the action listener so that the label is always there but it .setText and .updates when the item is selected as such: 我终于找到了解决方法,我在动作侦听器外部启动了标签,以使标签始终存在,但是当这样选择标签时,标签会是.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();
        }
    });

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

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