第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

如何創(chuàng)建以非活動(dòng)文本作為后綴的SWT文本字段?

如何創(chuàng)建以非活動(dòng)文本作為后綴的SWT文本字段?

LEATH 2022-09-14 17:34:45
我正在使用 Java 的 SWT 工具包創(chuàng)建一個(gè)包含文本字段輸入的 GUI。這些輸入字段需要數(shù)字輸入,并分配有單位。我正在嘗試創(chuàng)建一種花哨的方法,將字段中的單位作為文本的固定后綴進(jìn)行集成,以便用戶只能編輯數(shù)字部分。我還希望后綴灰顯,以便用戶知道它已被禁用 - 如下所示:在搜索時(shí),我看到了一些帶有Swing掩碼格式化程序的解決方案,這些解決方案可能會(huì)起作用,但我有點(diǎn)希望SWT可能存在一些默認(rèn)值。關(guān)于如何做到這一點(diǎn)有什么建議嗎?該字段是矩陣的一部分,因此我不能簡(jiǎn)單地將單位添加到標(biāo)題標(biāo)簽中。我想我可以在文本字段之后創(chuàng)建另一個(gè)列,以提供單位作為標(biāo)簽,但我要追求更直觀和更美觀的東西。有什么建議嗎?
查看完整描述

1 回答

?
楊__羊羊

TA貢獻(xiàn)1943條經(jīng)驗(yàn) 獲得超7個(gè)贊

一種選擇是將 和 小部件分組到同一個(gè)合成中,并將 上的文本設(shè)置為所需的后綴:TextLabelLabel

在此處輸入圖像描述

后綴左側(cè)的區(qū)域是可以編輯的單行文本字段,后綴是禁用的 。Label

public class TextWithSuffixExample {


    public class TextWithSuffix {


        public TextWithSuffix(final Composite parent) {

            // The border gives the appearance of a single component

            final Composite baseComposite = new Composite(parent, SWT.BORDER);

            baseComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));

            final GridLayout baseCompositeGridLayout = new GridLayout(2, false);

            baseCompositeGridLayout.marginHeight = 0;

            baseCompositeGridLayout.marginWidth = 0;

            baseComposite.setLayout(baseCompositeGridLayout);


            // You can set the background color and force it on 

            // the children (the Text and Label objects) to add 

            // to the illusion of a single component

            baseComposite.setBackground(new Color(parent.getDisplay(), new RGB(255, 255, 255)));

            baseComposite.setBackgroundMode(SWT.INHERIT_FORCE);


            final Text text = new Text(baseComposite, SWT.SINGLE | SWT.RIGHT);

            text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));


            final Label label = new Label(baseComposite, SWT.NONE);

            label.setEnabled(false);

            label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, true));

            label.setText("kg/m^3");

        }


    }


    final Display display;

    final Shell shell;


    public TextWithSuffixExample() {

        display = new Display();

        shell = new Shell(display);

        shell.setLayout(new GridLayout());

        shell.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));


        new TextWithSuffix(shell);

    }


    public void run() {

        shell.setSize(200, 100);

        shell.open();

        while (!shell.isDisposed()) {

            if (!display.readAndDispatch()) {

                display.sleep();

            }

        }

        display.dispose();

    }


    public static void main(final String[] args) {

        new TextWithSuffixExample().run();

    }


}


查看完整回答
反對(duì) 回復(fù) 2022-09-14
  • 1 回答
  • 0 關(guān)注
  • 127 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)