Using JTextArea, I would like for the first line to be a simple text (Title of the JTextArea).
Is there a way to make the text center align on the first line?
I don't think you can do this with a simple JTextArea. You might consider switching to a JTextPane, which supports HTML markup. The Java Tutorial How to Use Editor Panes and Text Panes shows an example.
Alternatively, you can just add a JLabel above your JTextArea where you display the title text.
Related
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.
Without resorting to wrapping a GWT TextArea in a separate DIV, how to add a search icon/magnifier icon inside the text area?
No, Not possible.Text area is not a normal Widget.
GWT's TextArea maps directly to a HTML TextArea thats why you can only set text to it. The only thing you can do ist create a Grid/VerticalPanel/HorizontalPanel and put in each cell a separate TextArea.
Google Groups
Similar Question
Use a Composite wrapping a FlowPanel, put a text area and an image inside, then in CSS position the icon absolutely so it's over the text field.
I'm currently developing JTextArea with a Notepad++ like function (currently indentation function finished).
Now I'm trying to add a function which in my JTextArea will show a dotted line for an indentation with same level, and change specific color of a word.
Thanks in advance :)
You will not able to achieve your target with JTextArea as it is a plain text support component.You have to use a Styled text supported JEditorPane or JTextPane.And try to use a HTML document and achieve it.Look at
Styled supported components
and
some more examples
I don't want to set the entire text area to bold but just a selected single line. How would go about doing that?
I suggest using a JTextPane instead as there are example solutions for it:
http://docs.oracle.com/javase/tutorial/uiswing/components/editorpane.html
http://www.java2s.com/Code/Java/Swing-JFC/JTextPaneStylesExample6.htm
There is no way to do it with JTextArea. You can achieve this with JEditorPane.
JEditorPane editorPane = new JEditorPane();
editorPane.setContentType("text/html");
editorPane.setText("<b>This text is bold</b>");
According to the documentation of JTextArea,
A JTextArea is a multi-line area that displays plain text.
plain text, in this sense, means every character is formated the same way. There is no way to format some characters differently than other characters.
I have a JScrollPane that holds a JLabel using the following code:
//Create TEXT LOG JPanel
textLogPane = new JScrollPane(logLabel);
textLogPane.setPreferredSize(textLogPaneDim);
//textLogPane.setOpaque(true);
textLogPane.setBorder(BorderFactory.createLineBorder(Color.BLACK));
textLogPane.getViewport().setBackground(Color.DARK_GRAY);
The JLabel, logLabel, is represented by a string with an HTML encoding using for carriage returns. I display certain images based on the contents of certain lines and I would like to be able to scroll the JScrollPane, textLogPane, to show that line whenever I am displaying that graphic. I know the contents of the line that I want to display but I can't seem to figure out how to get it to scroll down(or up) to the relevant line.
If need be I can change to something other than a JLabel as long as I can keep the HTML encoding and have it look just like multiple lines of text.
Sorry if this is a repeat I tried searching but couldn't find any results.
Thanks
You can do some custom maths and use scrollRectToVisible() in your viewport. I don't know how to compute the rect of a specific line in your JLabel. A better solution would be to stick your strings into a JList instead, perhaps with a custom renderer for the html, and use
list.ensureIndexIsVisible(list.getSelectedIndex());
You don't use "carriage returns" in HTML, you use "br" tags.
I would suggest you should probably be using a JTextPane for multiline text. I also find it easier to not use HTML, but instead to add strings with attributes. You can also insert icons into a JTextPane.
Read the section from the Swing tutorial on Using Text Components for a working example.