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?
Related
Ok, I am writing a text editor using a JTextPane. I am trying to figure out how to change the font size for specific text that the user types in. I have a JButton that the user can click to bring up a font-size and font-type selection menu. When the user selects the proper font size and type and presses ok, I then proceed to get the font size and type inside a Font. All I need to do now is to set the Font of the selected text in the JTextPane without overriding the current style(s) of the text. I haven't found anything that enables me to do this. Maybe I just missed something somewhere...
Thanks in advance.
Note: I am a newbie on StackOverFlow so please edit my question if I did something wrong.
Did you tried with this.
replaceSelection()
http://docs.oracle.com/javase/7/docs/api/javax/swing/JTextPane.html#replaceSelection(java.lang.String)
Use a styled editor kit and fire the actions inside the actionperformed method.
I tried to use the TextArea component to let user write multi-line text,
but the problem that I can't set the text alignment to right. By default it starts in the left.
The text will be in Hebrew or Arabic, so I need the user to write in the TextArea from right to left. I didn't find from the TextArea code and docs a way to do that, and in some forums some people said it can't be done. Is that true?
If you are using Scene Builder to build the FXML, then simply set Node Orientation property to RIGHT_TO_LEFT. You should see the result as soon as you run "Preview -> Show Preview in Window", where the cursor and typing happen on the righthand side.
If you are creating the TextArea inside a JavaFX application (no FXML), you use the method setNodeOrientation() on your TextArea object with the enum parameter NodeOrientation.RIGHT_TO_LEFT.
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 have a JTree that I have configured to be editable. When I triple click on the node to edit the underlying text field, it is drawn but the text is not selected and is not editable. The only way I can edit the node successfully is to navigate to another application and then back to the Java frame. It is as if when first trying to edit the text field is not receiving focus properly.
Does anyone know why I might be seeing this behaviour? The JTree has drag and drop enabled and also a MouseListener added to handle popup menus. Could these conflict with editing/focus somehow?
I am running on Fedora 14 using the latest Java 6u25 JDK.
The JTree has drag and drop enabled and also a MouseListener added to handle popup menus. Could these conflict with editing/focus somehow?
Remove that code and see what happens!
That is the point of creating a SSCCE. Start with basic code from the JDK to see how it works. Then, assuming it is working you add your custom code. When it stops working, you've isolated where the problem is and then maybe we can help.
I found the cause of the problem.
My application has a login frame that is hidden when the main frame is opened. A bug in the login frame meant that a text field was stealing the focus even though the frame had been hidden. This then caused problems with the text field on the JTree getting the focus on edit.
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.