Solved

How to add a title and a context info to the textbox in SWT?

Posted on 2013-06-19
1
315 Views
Last Modified: 2013-06-21
Hi,
I have a GUI and in this GUI I have a toolbar and a textbox under the toolbar.

I would like to add a title (named "Files in List") to the textbox field. (I marked it in red in the attachment)

Also, I would like to put some note into the textbox in light gray color to give some information to the user about how to use the textbox. But this light gray text should disappear when you click on the textbox field. (I marked it in blue in the attachment)

This is the code I used to create the text box. I added this code after the creation of all the tabs.

        //This is the text box
        GridData txtGridData = new GridData(GridData.FILL_BOTH); txtGridData.horizontalSpan = 2;
        Text txt = new Text(compTab1, SWT.MULTI | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL);
        txt.setLayoutData(txtGridData); 

Open in new window


I am sending a screen shot in the attachment to show the view.
text-box-title.png
0
Comment
Question by:Tolgar
1 Comment
 
LVL 16

Accepted Solution

by:
Valeri earned 500 total points
ID: 39264330
there is another widget called Group, it's used to implement your requirement. Just replace the code above with this one. Also add to your project attached file. To the text box is added FocusListener. When the text box gain the focus and the text is the one you want/description text/ it's cleared and foreground color is set to black. when focus is lost and there is nothig entered into the box the description text is set back and foreground color is set to gray.

GridLayout groupLayout = new GridLayout();
        GridData groupGD = new GridData(GridData.FILL_BOTH);
        Group groupText = new Group(compTab1, SWT.NONE);
        groupText.setLayout(groupLayout);
        groupText.setLayoutData(groupGD);
        groupText.setText("Files in List");
       
        GridData txtGridData = new GridData(GridData.FILL_BOTH);
        Text txt = new Text(groupText, SWT.MULTI | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL);
        TxtFocusListener txtFL = new TxtFocusListener(compTab1);
        txt.setLayoutData(txtGridData);
        txt.addFocusListener(txtFL);
        txt.setText(TxtFocusListener.introText); txt.setForeground(compTab1.getDisplay().getSystemColor(SWT.COLOR_GRAY));
TxtFocusListener.java
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
advertisement module in core php 4 160
diffSum example 4 36
Way to decrease size of apk file 9 67
maven module vs maven project 3 23
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question