Is there a way to do this with Java textareas? - java

I have a question relating to java textarea. I know I could probably accomplish a textarea by using swing, but there is a feature in my textarea I need that I don't know if the one in swing can do for me. I need it so that there is boolean H = false, when H = true and someone is typing, the text they type is hightlighted (simply want a color overlayed, not selected), and I need a way to save this highlight and be able to parse the text area for this highlight. I plan on using some Java Canvas to get what I want done, not including the textarea. I know if I wanted I probably could just program the textarea in the canvas, but I feel like this would be really complicated, and if I should use canvas is there any way I can make it so I can still click and drag to select areas of text?

Related

How to jtextField focus event in NetBeas

I made a landing interface in Java using NetBeans. I want to set when the textfield input format does not meet the requirements, then Red tips occur, how to achieve this? I know it is related to focus event, but I do not know the details
I suggest that use ActionEvent and ActionListener for textfield.
then use textfield.getText() to get String data.
you can now examine the String's content by separate it.
If you wanna check the format is a number or not, just use NumberFormatException.
https://docs.oracle.com/javase/7/docs/api/java/lang/NumberFormatException.html
after that,
you want a red warning tip, use label with color red, and .setVisible(boolean) to control it shows or not.

How to make an icon appear invisible without using a clear picture

I am making a program but the default Java icon looks really ugly, i want it so that the icon is clear without using any clear pictures, I'm using this code
f.setIconImage(new ImageIcon("pic.png").getImage());
so is there a way to do it? Or do i have to stick with a clear image?

Java swing - creating text field on button's place

When specific action is performed, I want to replace button with text field. I know that I have to call button1.setVisible(false); but I don't know how to create text field on the exact same place. I am using NetBeans designer, if you can give me a hint, how to add 2 components at same place, and switch between then, something like switching between layers in photoshop, if something like that is possible, would be great. Thanks
For many components in one space, use a CardLayout as see in this short example.

How to create a "Pick Whip" (Adobe After Effects) in Swing

In Adobe After Effects there is something called a "pick whip". It allows you to click on a dot on one object and drag a line from that dot to another element, making a connection between the two. I would like to duplicate this feature in my Java program using swing. I honestly have no idea where to start.
If I've done a bad job explaining what I mean, please comment so I can improve it. If there is some way outside of Swing to do this, I'm willing to try it.
Here are some examples of what I am trying to achieve:
LinePanel illustrates how to animate the line as it is rendered, but you'll have to paint on the glass pane or among JLayeredPane instances to see the line above existing components.

How to increase the height of Textarea in jtable dynamically

I have a standalone application in which I have a Jtable. In my table, when I type the text, the height of the Textarea should increase dynamically with the text. How can I do this?
Can someone help me with an example how to do this?
Thanking You
Chaithanya
It wasn't clear from your question - are you using a JTextArea or a TextArea? The reason it's ambiguous is people generally don't mix and match the light and heavy-weight frameworks (e.g. put awt components within a swing component).
If it's a JTextArea, I think your best bet is probably to use a DocumentListener.
DocumentListener myListener = ??;
JTextArea myArea = ??;
myArea.getDocument().addDocumentListener(myListener);
http://java.sun.com/docs/books/tutorial/uiswing/components/generaltext.html#doclisteners
I think what you'll need to do is listen for changes, and whenever something is added to the file, call the getLineCount() method, and compare it with the getRows() method. If it's broken the threshold, then use a setRows() call to increase the number of rows.
Will probably need to file some sort of UI change, especially to propagate up to the JTable.

Categories