jtextcomponent

How do I make the caret of a JTextComponent skip selected text?

假如想象 提交于 2019-12-10 10:11:22
问题 the normal behaviour of native text fields in many environments is as follows: Textfield with text "abcdefg". I use the mouse to select "efg" from left to right. The caret is now behind "g". When I move the caret to the left by pressing the cursor left key once, the selection is removed and the caret is right before "e". When I do the same in a JTextField or JTextArea (tested on Mac OS) doing the exact same thing results in the caret being right before "g". I know how I could change that

Reading a txt file in a Java GUI

蹲街弑〆低调 提交于 2019-12-08 13:54:28
问题 All I want to do is display the entire contents of a txt file. How would I go about doing this? I'm assuming that I will set the text of a JLabel to be a string that contains the entire file, but how do I get the entire file into a string? Also, does the txt file go in the src folder in Eclipse? 回答1: This code to display the selected file contents in you Jtext area static void readin(String fn, JTextComponent pane) { try { FileReader fr = new FileReader(fn); pane.read(fr, null); fr.close(); }

In Java Swing, can I receive Caret events in real time?

不问归期 提交于 2019-12-08 07:53:01
问题 I'm writing a hex editor-like view, which is composed of two JTextComponents (hex and ASCII). I'd like to synchronize the selection between the two views, so I've implemented a CaretListener for the two components. This works well for responding to selection events where the user has long-pressed, dragged, and released the mouse. The components receive the caretUpdate when the user releases the mouse. How can the components receive incremental caretUpdate events as the user presses the mouse

Smart JScrollPane autoscrolling

家住魔仙堡 提交于 2019-12-07 00:58:50
问题 I am attempting to implmement smart autoscrolling on a JScrollPane containing a JTextPane. The JTextPane is used for logging my app in color. However I'm running into a wall trying to do smart autoscrolling. By smart autoscrolling I don't mean blindly autoscrolling every time something changes, I mean checking to see if your scrolled all the way down, then autoscroll. However no matter what I do it either always autoscrolls or doesn't at all As a test script, here's the setup (the JFrame has

How do I make the caret of a JTextComponent skip selected text?

谁说胖子不能爱 提交于 2019-12-05 21:27:57
the normal behaviour of native text fields in many environments is as follows: Textfield with text "abcdefg". I use the mouse to select "efg" from left to right. The caret is now behind "g". When I move the caret to the left by pressing the cursor left key once, the selection is removed and the caret is right before "e". When I do the same in a JTextField or JTextArea (tested on Mac OS) doing the exact same thing results in the caret being right before "g". I know how I could change that programmatically by using a KeyListener and registering it with each component but I am looking for a way

Smart JScrollPane autoscrolling

▼魔方 西西 提交于 2019-12-05 07:07:26
I am attempting to implmement smart autoscrolling on a JScrollPane containing a JTextPane. The JTextPane is used for logging my app in color. However I'm running into a wall trying to do smart autoscrolling. By smart autoscrolling I don't mean blindly autoscrolling every time something changes, I mean checking to see if your scrolled all the way down, then autoscroll. However no matter what I do it either always autoscrolls or doesn't at all As a test script, here's the setup (the JFrame has been left out) final JTextPane textPane = new JTextPane(); textPane.setEditable(false); final

How to use html tags in JTextArea

橙三吉。 提交于 2019-12-04 19:08:10
问题 When I try to change color of a JTextArea using textArea.setText("<html> <font color=\"red\"> Hi </font></html>") , the text is shown is basically the whole text written inside setText method. But similar things work for JLabel, JButton etc. How can I do that for a JTextArea also? 回答1: don't to use JTextArea for Html formatted Object (even is possible, but why bothering) use JTextPane / JEditorPane instead (setContentType("text/html")) notice, todays Java and methods implemented in Official

How to use html tags in JTextArea

独自空忆成欢 提交于 2019-12-03 12:41:18
When I try to change color of a JTextArea using textArea.setText("<html> <font color=\"red\"> Hi </font></html>") , the text is shown is basically the whole text written inside setText method. But similar things work for JLabel, JButton etc. How can I do that for a JTextArea also? don't to use JTextArea for Html formatted Object (even is possible, but why bothering) use JTextPane / JEditorPane instead ( setContentType("text/html") ) notice, todays Java and methods implemented in Official API by Oracle supporting only reduced Html syntax with css <= Html 3.2 use JavaFX in the case that you want

how to make a Custom JTextComponent

若如初见. 提交于 2019-12-02 19:35:52
问题 I am trying to make a program that requires a couple of custom JTextComponents. For example I need something that acts like a small JTextArea with a different border (not a rectangular one), and some more rules about how to layout the text, characters per lines, max lines aloud, and formatting to fit into the non rectangular border. How do I properly extend JTextComponent so that people will be able to edit the text inside this the component? 来源: https://stackoverflow.com/questions/27334155

Arabic Typesetting font slowers my JTextArea, JTextPane and JTextEditor

倖福魔咒の 提交于 2019-12-01 12:33:36
I am using JTextArea to show heavy text in Urdu, Arabic and English language in Java. The problem is that my GUI freezes for 12-15sec when I use Arabic Typesetting font for JTextArea . I am getting text from XML and then showing in textarea, also using linewrap . My window also freezes for about 5sec when I re-size my window. Although on the console I am told that time taken for setting the text : 7.005 but when message shown it did not immediately show text in JTextArea but after about 5sec. The case is same for JTextArea, JTextPane and JTextEditor. Interestingly the above problems did not