chat room whit gif and emoji and image Java - java

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.

Related

How do I display the width of a JPanel after using getWidth();?

How would I display the width of a panel after using getWidth()? Can I put it in a JTextField/JTextArea? I don't think so, but I'm not sure.
It is certainly possible to display the panel size in a text component. You can use setText(String t) method to set the display text of a JTextField or a JTextArea. Try this:
String width = myPanel.getWidth();
myTextField.setText(width);
It will display the width of the panel to the user in a JTextField. (Or you can replace the text field to any text components you like)
You can also take a look at these two sections in the Java Tutorial: How to use Top-Level containers and Using Text Components. The Java Tutorial is a great official document for Swing developers.

Display hyperlinks in a jTextArea

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.

Append error message on jTextArea with different color

I was wondering if there is a way to append an error message in a jTextArea with different font color.
Like this it will make a difference between the normal output that I am appending and the error output.
For example, on Netbeans the system.err font color is red, and the System.out is appearing black.
JTextArea only allows a single color to be used. You can use a JTextPane instead
Two Swing classes support styled text: JEditorPane and its subclass JTextPane. The JEditorPane class is the foundation for Swing's styled text components and provides a mechanism through which you can add support for custom text formats.
If you want unstyled text, use a text area instead.
Source :Styling Dynamically
I afraid it is not possible to display colored text in jtextarea. you can only do that on jtextpane and here how .

how to make java run time sizable image box

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.

In Swing, what is the best listener to use in a textarea

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.

Categories