Which parameter of this JTextArea should I change? - java

I'd like to know which parameter of my JTextArea I should change in order to remove this:
I want the text area to be blank and I don't want the possibility to navigate it with this brackets (?)

If you want to prevent the Scroll Bars from appearing for a JTextArea then change the Horizontal and Vertical Scroll Bar Policies for the JScrollPane that wraps that JTextArea:
jScrollPane1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
jScrollPane1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);

Related

How to display content in a JTextArea or ScrollPane

I input into a text field "C". What should be displayed should be the next 10 letters that come after C. What I could do is convert all these letters into strings and then set the strings text to a JLabels text, but instead I want to be able to show them on a textArea with a scroll pane so that it doesn't run off the page and instead stays within a window I can scroll down from.
Is there any way to accomplish this? I have a TextArea fitted with a scroll pane setup, but I don't know how to output any data here.

How to under-line selected text in JtextArea

I want to make selected text of jtextarea underline while clicking a spicified button. this task I have accomplish in jtextpane but I need it in jtextarea any suggestions please.
Use a JTextPane (or JEditorPane), where you can use HTML tags to accomplish that.
The text of a JTextArea cannot be formatted in parts, as indicated here, for example:
A JTextArea is a multi-line area that displays plain text.
I want to make selected text of jtextarea underline
You can add a Highlighter to the text area and use a custom Painter to highlight the text. The default painter paints the entire background of the highlighted text, but you can customize the Painter to do whatever you want.
Check out Rectangle Painter for a couple examples of creating your own custom Painter.

Change cursor aligment vertically in multi-line JTextField

I have the following JTextField where I would like to change the cursor position from the middle to the TOP of the JTextField:
How do I accomplish that?
There is no such thing as a multi-line JTextField. What you posted is a regular, single-line JTextField which is simply stretched out.
If you need mutli-line text components, consider using a JTextArea or JTextPane in which you can perfectly set the cursor (caret) at the first line
Edit
Just read your comment. An editable textfield for output is just confusing to the user. At least make it non-editable, or opt for a JLabel with a Border

Scrollbar in html component in lwuit java

I want to create chat window with textarea and textbox in lwuit. Textarea must capable to show smiley and coloring text. I have used HtmlComponent of lwuit and facing problem in scrollbar. As text content grows in size, whole screen scroll including textbox. I want only content of textarea to be scrolled.
How to solve it?
well, you can forbid scrolling for the whole form using
Form.setScrollable(false).
Then you just set your HTMLcomponent scrollable "true" with the same method and finally put these two components (TextArea and HTMLComponent) to a different cosntraints (e.g. TextArea in BorderLayout.NORTH and HTMLComponent in BorderLayout.CENTER)

Reflowing label widget for Swing

Is there a widget for Swing that behaves like a JLabel, that automatically reflows the text if its dimensions have changed? For example:
Large horizontal space available:
+--------------+
| Foo bar baz |
+--------------+
Small horizontal space available:
+---------+
| Foo bar |
| baz |
+---------+
I am currently using JEditorPane with setContentType("text/html") and HTML content. This works, but it does not use the System's default label font for displaying the text. Also, I would rather not put HTML tags into my text - at best, \n characters would be transformed into line breaks and everything else would be displayed as text.
You can use JTextArea, a multi-line plain-text widget.
JavaDoc: http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/JTextArea.html
JTextArea ta = new JTextArea("A JTextArea containing a long text");
ta.setLineWrap(true);
ta.setWrapStyleWord(true);
ta.setOpaque(false);
ta.setEditable(false);
ta.setFocusable(false);
setLineWrap(true) enables the wrapping
setWrapStyleWord(true) changes wrapping from character- to word-based
setOpaque(true) renders it opaque, like a normal label
setEditable(false) hides the caret and disables the user to change the text
setFocusable(false) disables the user to select the text
It look like a nornal JLabel, but it will wrap the text, whenever the width is too small.
I'm not sure of this, but I think it's worth a try:
You can set a JLabel's text using HTML. This should take care of the font issue. Simply do something like
lbl.setText("<html><body>Foo bar baz</body></html>");
See how the text behaves then.
If that works for you, you can override JLabel's setText() method to convert \n into <br/> and wrap html and body tags around the text.
I have made a custom UI delegate for JLabel to support multiple lines. It will wrap your text to fit the available space and also respect hard line breaks. The wrapped text should reflow when the component size changes. The UI delegate listens for changes to the component's dimension and recalculates the line breaks automatically.
Using the UI delegate is as straight forward as:
JLabel label = new JLabel("Text that'll wrap if necessary");
label.setUI(MultiLineLabelUI.labelUI);
Or alternatively use the custom MultiLineLabel class that in addition to wrapping text supports vertical and horizontal text alignment.
Here's the project: https://github.com/sasjo/multiline
If you compile and try the demo, it should reflow fine on OS X. If I remember correctly there's some problem with reflowing upon resizing the frame on Windows. Didn't look in to it at the time, but it seemed that the resized event never propagated to the label.

Categories

Resources