I did a search engine where I can enter some words and find the links where this words appears. But when I display this links, I am displaying it as string, and I want to display it as hyperlinks, that the user can click and connect to the site. I used the solutions I found here on stackoverflow, but none of then worked.
Does anyone knows how can I do it? At the moment, I am displaying the results inside a jTextArea.
I am displaying the results inside a jTextArea
You can't use a JTextArea. A JTextArea only displays simple text.
You need to display HTML in a JEditorPane and add the links using HTML. Then you add a HyperLinkListener to the editor pane.
Read the section from the Swing tutorial on How to Use Editor Panes for general information and examples.
Read the JEditorPane API for an example on how to create a HyperLinkListener and respond to mouse clicks.
Related
in my JAVA FX application I am using TextArea to display certain text content. I am using following property to restrict editing:
templateScriptArea.setEditable(false);
With this, user is not able to write anything on TextArea, but selection is allowed, or if any selection is made by application is able change by user.
My requirement is that TextArea should be completely readonly, no editing no selection. Only scroll should work.
I thought, disabling TextArea is good idea with :
templateScriptArea.setDisable(true);
But, scroll not work with this and grey color appears on TextArea.
Is there any better solution?
I want to build a chat room whit java swing.
I want to have a component to show text, image, gif and emoji.
please help me to select a good component.
In first I choose JtextPane for this.Is it good?
In first I choose JtextPane for this.Is it good?
Yes, I would use a JTextPane, with normal text (not HTML). With a JTextPane you can:
text with attributes.
align text to the right/left of the text pane
display icons using the insertIcon(...) method.
Read the section from the Swing tutorial on Text Component Features for some examples that use attributes when adding text.
I have been researching this topic a lot and haven't found anything that tells me I can add a BufferedImagento a JTextArea or JTextField. I am making a chat application and trying to add smiley faces for the chat. What I am trying to do is put the image right next to the string like it is text. I was thinking if you could put the Buffered image in the format of a char that would help. Please help me! Thank you!
I'd also give a try to JEditorPane.
For motivation see: http://www.apl.jhu.edu/~hall/java/Swing-Tutorial/Swing-Tutorial-JEditorPane.html.
I've noticed that most of the chat applications, show you what you and others wrote in one window (could be JEditorPane with all the smilies displayed as pics) and bellow you can have editable JTextArea showing just text.
The problem is that JTextArea and JTextField, are really only meant to show text, in order to implement something that mixes thetext with images, you would need to extend JTextArea and modify the paintComponentMethod to do custom rendering.
I'm making a Unicode translator in Java. I did all hard parts, but now I want to add a resizable, relocatable image to the textpane. The user must be able to resize image with its corners and drag & drop the image within the textpane where he likes. (like Microsoft Word or Photoshop)
Something like this:
I tried the Styled Document properties. But I couldn't find way except inserting only an ImageIcon.
May be a better choice would be not to use textPane.
If you have an custom editable label, that can be edited by double clicking on it to show a text box to edit the contents, and change the text of the label when enter key is pressed.
Also give a shot of JDesktoppane, JLayeredPane, and check what components can be added to it.
try this
http://mgeisler.net/downloads/browser/src/ImageBox.java.html
try loading the image inside a JLabel component in JFC Swing.
Otherwise try some other non editable components in the same technology with resizable property.
try this http://sourceforge.net/projects/ird/
the iRD is a component for Resize and move(drag&drop) compoennts on runtime in java.
I am trying to change the font of the text in a textarea in Swing. Which listener should I use on textarea to trigger an action that lets the program initiate the font code.
All the examples have all the swing in the same class which lets you access the textarea directly, but I have multiple classes; I know I can pass the textarea in and in and in, but this is sloppy.
I just cannot figure out which listener to initiate.
I am trying to change the font of the
text in a textarea in Swing.
Well a JTextArea can only have a single Font, so if you want to change the Font you would have some other component, maybe a "Change Font" button that you would click. In this case you would add an ActionListener to the button to change the actual Font of the text area.
If you actually need to change the Font on selected pieces of text, then you also can't do this with a JTextArea. You would need to use a JTextPane. Read the JTextPane API and follow the link to the Swing tutorial on "Text Component Features" for an example of changing attributes on selected text. In this cause you use Actions provided by the editor kit.
So basically you need to read the Swing tutorial to find out the basics of using Swing components.
If you're listening to the textarea, then it would depend on how many different ways you want the user to be able to change the font of what they are typing.
You could use MouseListener if you want them to be able to change the font on right click/etc... or a KeyListener if you want to listen for a series of keys.