jtextarea

Save a the text from a jTextArea (ie Save As) into a new .txt file

末鹿安然 提交于 2019-12-19 10:23:15
问题 I am busy trying to make a word processor as one of my project and I need the text entered into the jTextArea to be saved as a .txt file with a name and location that the user chooses. note "fc" is the name of i file chooser i have already declared. public class TextEditor extends javax.swing.JFrame { int count = 2; JTextArea n = new JTextArea(); final JFileChooser fc = new JFileChooser(); public void SaveAs() { final JFileChooser SaveAs = new JFileChooser(); SaveAs.setApproveButtonText("Save

Java JTextArea dynamic column and row numbering

南笙酒味 提交于 2019-12-19 09:44:05
问题 I've had a quick Google around, and I can't seem to find a good solution to this, mostly because I'm not sure how to describe it. Essentially, I need to display an arbitrary amount of hex characters in a JTextArea , and I'd like to have them spaced evenly, and have the positions of the characters shown at the top and left of the characters. This is an example of what I'd like to achieve, this is the hex viewer WinHex. I've been playing around with converting a byte array to a String, and then

How to limit JTextArea max Rows and Columns?

六眼飞鱼酱① 提交于 2019-12-19 03:58:43
问题 I am using JTextArea in JScrollPane I want to limit the maximum number of lines possible and the maximum chars in each line. I need that the string will be exactly like on the screen, each line will end with '\n' (if there another line after it) and the user will be able to insert only X lines and Y chars in each line. I tried to limit the lines but I don't know exactly how many lines do I have because of the line wrapping, The line wrapping is starting new line visually on the screen(because

JScrollPane scrolling with arrow keys

时间秒杀一切 提交于 2019-12-18 11:32:01
问题 I've a JTextArea component inside JScrollPane and the text area is not editable. I would like to enable scrolling of the text area with up and down arrow keys (i.e. pressing the arrow keys will scroll the text area by one line). Any ideas how to achieve this? 回答1: Yes Key Bindings is the way to go, but you don't always need to create your own actions. Swing components come with default Actions that you can often reuse. See Key Bindings for a complete list of these Actions. Now that you know

Highlight one specific row/line in JTextArea

梦想的初衷 提交于 2019-12-18 07:26:22
问题 I am trying to highlight just one specific row in JTextArea , but I have no idea as to going about it. I need to get the specific row and then highlight it. I've read the other posts, but I still do not understand how to bring it together to solve my problem...help would be much appreciated. 回答1: Try your hands on this code example, and do ask if something is not clear : import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.text.*; public class TextHighlight {

Custom CellEditor with JScrollPane - start editing issue

北战南征 提交于 2019-12-17 20:33:03
问题 I have a JTable with a custom CellEditor using a JTextArea inside a JScrollPane. It works perfectly when I enter edit mode via mouse clic. However, when I try to type some letter while a cell is focused, nothing happens. The cell gets the "edit mode style" (the background changes), but stays empty... Any idea ? public class MultiLineCellEditor extends DefaultCellEditor { JTextArea textArea; JScrollPane scrollPane; public MultiLineCellEditor( final JTable table ) { super( new JTextField() );

JTextArea setText() & UndoManager

[亡魂溺海] 提交于 2019-12-17 19:54:14
问题 I'm using an UndoManager to capture changes in my JTextArea . The method setText() however deletes everything and then pastes the text. When I undo I firstly see an empty area and then it would show which text it had before. How to reproduce: Run the following code Click the setText() button Press CTRL+Z to undo (you'll see an empty textarea!) Press CTRL+Z to undo (you'll see the actual previous text) I want to skip 3). import javax.swing.AbstractAction; import javax.swing.JFrame; import

MigLayout JTextArea is not shrinking when used with linewrap=true

萝らか妹 提交于 2019-12-17 19:39:05
问题 If I use a JTextArea with MigLayout like this: MigLayout thisLayout = new MigLayout("", "[][grow]", "[]20[]"); this.setLayout(thisLayout); { jLabel1 = new JLabel(); this.add(jLabel1, "cell 0 0"); jLabel1.setText("jLabel1"); } { jTextArea1 = new JTextArea(); this.add(jTextArea1, "cell 0 1 2 1,growx"); jTextArea1.setText("jTextArea1"); jTextArea1.setLineWrap(false); } then the JTextArea grows and shrinks perfectly when resizing the window. When I set the linewrap to true the JTextArea is not

How can I create a JTextArea with a specified width and the smallest possible height required to display all the text?

天涯浪子 提交于 2019-12-17 19:38:57
问题 In all the examples that I can find that use a JTextArea , the height & width is known before constructing the JTextArea , and if the JTextArea would require more height, then it is put inside of a JScrollPane . Obviously, the height of JTextArea is dependent on the width and the text contents. Now, my situation requires that I do not use a JScrollPane , but instead that the JTextArea be just tall enough to display all the text. When I create the JTextArea , I know the text contents and how

Java :Add scroll into text area

南楼画角 提交于 2019-12-17 18:49:04
问题 How can i add the scroll bar to my text area. i have tried with this code but it's not working. middlePanel=new JPanel(); middlePanel.setBorder(new TitledBorder(new EtchedBorder(), "Display Area")); // create the middle panel components display = new JTextArea(16, 58); display.setEditable(false); // set textArea non-editable scroll = new JScrollPane(display); scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); //Add Textarea in to middle panel middlePanel.add