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.
Related
I am trying to print particular images(which include some drawn symbols) on textarea when I type a particular Alphabet on my keyboard. How?
You can't use a JTextArea since it can only display text.
You can use a JTextPane as it supports the display of Icons.
Check out: Auto Replace Smiles. It shows how to replace the two text characters :) with an Icon.
You are asking me to do your homework, but still. I will give you only the pseudo code, you will have to write it on your own.
Write a JFrame.
Add a JLabel to the JFrame (using a label is easier than using a text pane, and it is impossible to use a text area).
Add a Key Listener to either the JFrame or the JLabel depending on your application.
In the handler write code to add a ImageIcon to the JLabel when the key you want is pressed or whatever.
Cheers!
I'm pretty new to Java and have been stuck for hours trying to figure out how to do the following...
I would like to create a Java program that shows a panel (has a background image that is scrollable) that contains input boxes. Think of a panel that shows at 800by800, but the image is more like 2000x2000, with input boxes all over. As you scroll, nothing should move.
I'd be very greatful if anyone can point me the right direction or has a sample piece of code that they would share.
Thank You!
You could try a JScrollPane: JScrollPane
I'm creating a chat program, similar to IRC. With my client though, I have the problem that when text is added to a JTextPane (using a GridBagLayout), it resizes instead of wordwraps. Well, it actually will wordwrap eventually, but it shouldn't be resizing. Here is what I mean:
I could set the JTextPane dimension to an exact number, but I want the user to be able to resize the window, and the parts inside as needed. How can I get to put as much text in without it resizing?
I ended up fixing it by adding setting it into a JScrollPand and using .setPreferredSize().
I'm writing a simple text editor in java, I have done it before now I have some new ideas, normally when I put in a JTextArea when I have a FlowLayout on my JFrame it will fill what is left of the JFrame. However this time it's not. Could someone help me out trying to get it to fill the rest of my JFrame? Thanks!
http://docs.oracle.com/javase/tutorial/uiswing/layout/layoutlist.html
Java does have various layouts. For making dynamic body changes you have to learn more flexible layouts like grid or grid bag layout. Hope this help.
I want a scrollable console within a JFrame, so people can see messages while using the GUI.
I'm currently using a JLabel, but this obviously only allows one message at a time.
Have you checked the JTextArea Swing component?
This tutorial should help you as there is a scrollable text area in one of the samples: http://download.oracle.com/javase/tutorial/uiswing/components/textfield.html
Use a JEditorPane, it is the most flexible.
I'd suggest you JTextArea or JScrollPane.