jtextarea

Retrieving a double from a JTextArea while solving for X

对着背影说爱祢 提交于 2019-12-24 03:29:10
问题 Ok, I'm kinda new to java. I'm making a program that solves for one step equations. I'm having some difficulties running it though. Here is the code for my main file, Main.java : import javax.swing.*; import java.awt.*; import java.awt.event.*; public class Main extends JFrame implements ActionListener { private static final long serialVersionUID = 1L; Solve solve = new Solve(); JButton add = new JButton("Add"); JButton sub = new JButton("Subtract"); JButton mult = new JButton("Multiply");

Highlight Text In JTextArea In Presence of Duplicate Lines

Deadly 提交于 2019-12-24 03:20:57
问题 I have a JTextArea which consists of lines (some of them possibly duplicates of one another). I've a requirement where I've to highlight the selected line upon right-click. The code that I'm using to highlight is as follows: String highlightedText = textArea.getSelectedText(); if(highlightedText != null) { try{ int index = textArea.getText().indexOf(highlightedText, textArea.getCaretPosition()); textArea.getHighlighter().addHighlight(index - 1, index + highlightedText.length(), new

Add a line at a time to a String

杀马特。学长 韩版系。学妹 提交于 2019-12-24 03:17:04
问题 I have this program that lets you open a file and it reads it in to a JTextArea all at once using the following code: try{ String fileContents = new Scanner(new File(fileName)).useDelimiter("\\Z").next(); }catch(FileNotFoundException ex){ ex.printStackTrace(); } myTextArea.setText(fileContents); and this works. But my question is how can I read this into my fileContents string and still have it add in the line breaks every time I get a new-line character? Here is what I have, but this puts it

Append Text to JTextArea on Multiple Lines?

与世无争的帅哥 提交于 2019-12-24 02:44:36
问题 I have a string with multiple numbers, when printed out it looks something like this: 2 4 5 10 20 25 50 However, when I append the string to a JTextArea it looks like this: 24510202550 How can I make the JTextArea look like the ouput with the numbers on seperate lines? Thanks! 回答1: You're probably using System.out.println() to print to console. The System.out.println() will add '\n' character to the end of each line for you. But to output strings to JTextArea in same way use jTextArea.append(

Which event a selection of text trigger in Java JTextArea?

蓝咒 提交于 2019-12-24 02:26:10
问题 I want to monitor the selection of text into the a JTextArea. I don't know what event a selection of text triggers. I just want to enable some of the menu items as soon as some text is selected out of the JTextArea like copy and cut options into the menu. What should I monitor for that? 回答1: I don't know about any "selection listeners" for text components (although they might be useful), but you could use a CaretListener to monitor changes to the caret position and check the selection state..

Which event a selection of text trigger in Java JTextArea?

故事扮演 提交于 2019-12-24 02:26:05
问题 I want to monitor the selection of text into the a JTextArea. I don't know what event a selection of text triggers. I just want to enable some of the menu items as soon as some text is selected out of the JTextArea like copy and cut options into the menu. What should I monitor for that? 回答1: I don't know about any "selection listeners" for text components (although they might be useful), but you could use a CaretListener to monitor changes to the caret position and check the selection state..

Java - how do I gain focus on JTextArea when selecting a new JTabbedPane

荒凉一梦 提交于 2019-12-24 01:49:07
问题 I have a swing GUI with multiple JTabbedPane s; each tab contains two JButtons at the top, then a JTextArea (for user input), and a JTextField at the bottom for a result. My problem is that I can't get the JTextArea to gain focus after switching tabs without either clicking in it with the mouse or using the tab key on the keyboard? I have... frame.addWindowFocusListener(new WindowAdapter() { public void windowGainedFocus(WindowEvent e) { textArea_1.requestFocusInWindow(); ...and this works

location and size of jtextarea in jscrollpane is not set

蓝咒 提交于 2019-12-24 00:56:38
问题 I am working on the editor. I am using Java swing for it. I have embedded a JTextArea with JScrollPane . i want to position the jtextarea of particular size at the middle of JScrollPane . To do this I used setLocation function. But this is not working? public class ScrollPaneTest extends JFrame { private Container myCP; private JTextArea resultsTA; private JScrollPane scrollPane; private JPanel jpanel; public ScrollPaneTest() { resultsTA = new JTextArea(50,50); resultsTA.setLocation(100,100);

JOptionPane with a JTextArea instead of a text field?

岁酱吖の 提交于 2019-12-23 15:54:17
问题 I need to grab multiple lines of input from a popup JOptionPane (or some other popup, but most of my searches direct me there, which is where I get stuck..). I am stuck at using JOptionPane.showInputDialog(null, new JTextArea(20,20)); but I want just the 20x20 area to be read to a String and no text field shown. I figure there must be some way to do this, but the other types of dialog only seem to return an int... It doesn't have to be a JOptionPane, as long as it is a separate popup from my

How to bind swing.JTextArea to PrintStream to accept data

点点圈 提交于 2019-12-23 15:03:11
问题 Client has gui and extra thread (to process socket input and print it out to passes object of type PrintStream). The gui form has new javax.swing.JTextArea() . I need to pass to thread the object PrintStream to write to: ClientThreadIn(PrintStream inOutput){...} . How to create/bind gui JTextArea to accept data form ClientThreadIn using PrintStream ? Client: in = new BufferedReader(new InputStreamReader(s.getInputStream())); out = new PrintWriter(new OutputStreamWriter(s.getOutputStream()));