Hiding cursor in Text component in Eclipse RCP application - eclipse

In my eclipse RCP application there are a few buttons & few input boxes & this below Text component. My problem is as soon as I press one of the buttons a cursor starts blinking in the below test component. Can you please let me know how to solve this.
I tried:
setting focus to false for Text.
SWT.READ_ONLY for Text .
Code:
Cursor cursor = new Cursor(parent.getDisplay(), SWT.CURSOR_NO);
protocolFilterDescription.setCursor(cursor);
Nothing seems to get rid of this unnecessary cursor.
protocolFilterDescription = new Text(parent, SWT.NONE | SWT.READ_ONLY );
FormData protocolFilterDescriptionLData = new FormData();
protocolFilterDescriptionLData.left = new FormAttachment(0, 1000, 650);
protocolFilterDescriptionLData.top = new FormAttachment(0, 1000, 290);
protocolFilterDescriptionLData.width = 450;
protocolFilterDescriptionLData.height = 12;
protocolFilterDescription.setLayoutData(protocolFilterDescriptionLData);
protocolFilterDescription.setForeground(new Color(parent.getDisplay(),
204, 153, 0));
protocolFilterDescription.setBackground(Display.getCurrent()
.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
protocolFilterDescription.setFont(new Font(parent.getDisplay(),"Verdana",
6, 1));
protocolFilterDescription
.setText("captured");

You have to set the focus of some other SWT component to true to remove the focus from the Text component.
You'll probably have to do this in an ActionListener.

If you want to completely remove the cursor from the Text control (which implies inability to perform a selection there, etc), try calling setEnabled(false) on it.
Also, such requirement suggests that you maybe don't need Text component at all, and could use Label instead.

Related

How to set the color of a text in TextField for Harmony OS?

How to set the color of a text in TextField? For example, set the "Harmony" font in the "Hello Harmony" field to red The Android code is implemented as follows:
SpannableStringBuilder ssb = new SpannableStringBuilder(); ssb.setSpan(new ForegroundColorSpan(getCurrentHintTextColor()), i, i + 1, 0);
Can use RichText for Harmony OS, you can achieve the same effect. Please see below screenshot for the sample code, which will set Harmony to red.
Text text = ComponentHelper.getShapeText( context: this);
text.setTextSize(80);
RichTextBuilder builder = new RichTextBuilder);
TextForm redForm = new TextForm();
redForm.setTextColor(Color.RED.getValue(0);
redForm.setTextSize(50);
builder.mergeForm(redForm);
builder.addText("Harmony");
TextForm blackForm = new TextForm();
blackForm.setTextColor (Color.BLACK.getValue ());
blackForm.setTextSize(60);
builder.mergeForm(blackForm);
builder.addText("OS");
text.setRichText(builder.build());
RichTextBuilder and TextForm Links are below:
https://developer.harmonyos.com/en/docs/documentation/doc-references/richtextbuilder-0000001054358740
https://developer.harmonyos.com/en/docs/documentation/doc-references/textform-0000001054120081

How to place widgets like labels & buttons with `.pack()`?

Hello i am asking for help on a PyDev Eclipse problem i cold not find a solution on at this forum. My example below show that i have a window with a couple of labels and buttons etc. But the ting is that when i searched earlier i found posts on how to place widgets using .grid() and .place() but not any for .pack() which i am using. Therefor i want to know what would be the best way for me to place these widgets for example in the center of the parent window.
Thanks in advance. :D
window.title("PTF Pydev Eclipse")
window.geometry("500x500")
window.config(bg="blue")
frame = tk.Frame(window, bg="blue")
lbl = tk.Label(frame, text= "secret")
lbl.config(background="blue", width="500")
ent = tk.Entry(frame)
lbl1 = tk.Label(frame, text= "secret", bg="blue")
ent1 = tk.Entry(frame)
lbl2 = tk.Label(frame, text= "secret", bg="blue")
btn = tk.Button(frame, text="secret", command= lambda: validation())
btn2 = tk.Button(frame, text="secret", command=lambda: page1())
lbl3 = tk.Label(frame, bg="blue", text="secret")
ent2 = tk.Entry(frame) #these 3 are packed in a function (not included).
lbl.pack()
ent.pack()
lbl1.pack()
ent1.pack()
lbl2.pack()
btn.pack()
frame.pack()
window.mainloop()
Do not use pack if you want to control the exact position of each widget.
Your window is 500x500, right ?
So for example if you want to place a widget at the top left of your window, you could to
Yourwidget.place(x=10, y=10)
Hope It helps, good luck.

ITextSharp errror "Off is not a valid name for a checkbox appearance (should be Off or Yes)"

Running the following code snippet under VS 2010 using iTextSharp 5.5.6:
PdfReader reader = new PdfReader("Test.pdf");
FileStream fs = new FileStream("New.pdf", FileMode.Create);
PdfStamper p = new PdfStamper(reader, fs);
AcroFields form = p.AcroFields;
...
RadioCheckField newField = new RadioCheckField(p.Writer, new iTextSharp.text.Rectangle(20, 20), "MyCheckBox", "Off");
PdfFormField RadioField = newField.CheckField;
p.AddAnnotation(RadioField, 1);
I receive the error "ITextSharp errror "Off is not a valid name for a checkbox appearance (should be Off or Yes)" at the line declaring the RadioField object. Is this a bug? How do I work around it?
A check box can have two values:
one you define yourself in your method. That will be the value of the check box when selected.
one that is defined in ISO-32000-1: Off. That's the value of the check box when it's not selected.
There is a bug in your code because you are trying to create a check box of which the value is always Off whether it's selected or not.
Choose another value. Off is reserved for the off state. You need yo define a value for the on state. ISO-32000-1 recommends Yes.
This is how you make sure the check box is selected:
newField.Checked = true;
Unchecked is done like this:
newField.Checked = false;

Why scrollbar of JtextArea doesn't navigate?

I use one JTextArea and JScrollBar. It has this problem when I run it and it will fill by text, I can't navigate it. i.e. when I click on arrowkey on scrolbar, nothing happen. although I write the update code for it (by using API), but it doesn't work well. What shall i do? Thanks in advance.
I show my code as bellow:
JTextArea Result_field = new JTextArea(5,10);
Result_field.setPreferredSize(new Dimension(5, 10));
JScrollPane scrollPane = new JScrollPane( Result_field );
scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
DefaultCaret caret = (DefaultCaret)Result_field.getCaret();
caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);
PrintStream printStream = new PrintStream(new CustomOutputStreamm(Result_field));
System.setOut(printStream);
MainPanel.add(scrollPane,gbc);
I found out my problem, although we define one JTextArea or ... by the size, But after that we should determine the prefer size again.

How do i set the scrollbar in JScrollPane to the top? Using borderlayout. the bar always scroll to the bottom of my content.

//created a JScrollPane and when i run it the scrollbars will automatically go to the most bottom of my textarea, but i need it to be on top.
thank you in advance! =)
JScrollPane scrollPane = new JScrollPane();
scrollPane.setBounds(22, 86, 262, 57);
content.add(scrollPane);
//the text area used
JTextArea txtrTryingTryingTrying = new JTextArea();
scrollPane.setViewportView(txtrTryingTryingTrying);
txtrTryingTryingTrying.setText("-------");
I've been trying as well, and found a solution.
There is a useful method called: setCaretPosition(int)
After you use
component.setText("Text here");
You must use
component.setCaretPosition(0); //0 will set it to the top
In your case, you must add setCaretPosition() after setText
JTextArea txtrTryingTryingTrying = new JTextArea();
scrollPane.setViewportView(txtrTryingTryingTrying);
txtrTryingTryingTrying.setText("-------");
txtrTryingTryingTrying.setCaretPosition(0);