List of usage examples for javax.swing JTextArea setText
@BeanProperty(bound = false, description = "the text of this component") public void setText(String t)
TextComponent
to the specified text. From source file:TextAreaViews.java
public static void main(String[] args) { try {// w ww. j a va 2 s . co m UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); } catch (Exception evt) { } JFrame f = new JFrame("Text Area Views"); JTextArea ta = new JTextArea(5, 32); ta.setText("That's one small step for man...\nOne giant leap for mankind."); f.getContentPane().add(ta); f.setSize(200, 100); f.setVisible(true); ViewDisplayer.displayViews(ta, System.out); try { Thread.sleep(30000); ViewDisplayer.displayViews(ta, System.out); } catch (InterruptedException e) { } }
From source file:CornerCaret.java
public static void main(String args[]) { JFrame frame = new JFrame("CornerCaret demo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextArea area = new JTextArea(8, 32); area.setCaret(new CornerCaret()); area.setText("This is the story\nof the hare who\nlost his spectacles."); frame.getContentPane().add(new JScrollPane(area), BorderLayout.CENTER); frame.pack();/*from ww w . j a v a2 s. c om*/ frame.setVisible(true); }
From source file:FancyCaret.java
public static void main(String args[]) { JFrame frame = new JFrame("FancyCaret demo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextArea area = new JTextArea(8, 32); area.setCaret(new FancyCaret()); area.setText("VI\tVirgin Islands \nVA Virginia\nVT\tVermont"); frame.getContentPane().add(new JScrollPane(area), BorderLayout.CENTER); frame.pack();//from w ww . j a v a2 s . com frame.setVisible(true); }
From source file:Main.java
public static void main(String... args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel contentPane = new JPanel(); contentPane.setLayout(new GridLayout(1, 2, 2, 2)); JTextArea tArea1 = new JTextArea(); tArea1.setLineWrap(true);/* www. j ava2 s . c o m*/ JTextArea tArea2 = new JTextArea(); tArea2.setLineWrap(true); tArea1.setText("I got a long long line of text in my JTextArea"); tArea2.setText("I got a long long line of text in my JTextArea"); JScrollPane scroller1 = new JScrollPane(); JScrollPane scroller2 = new JScrollPane(); scroller1.setViewportView(tArea1); scroller2.setViewportView(tArea2); contentPane.add(scroller1); contentPane.add(scroller2); frame.setContentPane(contentPane); frame.setSize(100, 100); frame.setLocationByPlatform(true); frame.setVisible(true); }
From source file:LineHighlightPainter.java
public static void main(String args[]) { // extend DefaultCaret as an anonymous inner class Caret lineHighlightPainterCaret = new DefaultCaret() { private Highlighter.HighlightPainter lhp = new LineHighlightPainter(); // override getSelectionPainter to return the LineHighlightPainter protected Highlighter.HighlightPainter getSelectionPainter() { return lhp; }/*from w w w . j a v a 2s .co m*/ }; JFrame frame = new JFrame("LineHighlightPainter demo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextArea area = new JTextArea(9, 45); area.setCaret(lineHighlightPainterCaret); area.setLineWrap(true); area.setWrapStyleWord(true); area.setText("This is the story\nof the hare who\nlost his spectacles."); frame.getContentPane().add(new JScrollPane(area), BorderLayout.CENTER); frame.pack(); frame.setVisible(true); }
From source file:com.novadart.silencedetect.SilenceDetect.java
public static void main(String[] args) { // create the parser CommandLineParser parser = new BasicParser(); try {//from w w w .j a v a 2 s . c om // parse the command line arguments CommandLine line = parser.parse(OPTIONS, args); if (line.hasOption("h")) { printHelp(); } else { String decibels = "-10"; if (line.hasOption("b")) { decibels = "-" + line.getOptionValue("b"); } else { throw new RuntimeException(); } String videoFile = null; if (line.hasOption("i")) { videoFile = line.getOptionValue("i"); Boolean debug = line.hasOption("d"); if (line.hasOption("t")) { System.out.println(printAudioTracksList(videoFile, debug)); } else if (line.hasOption("s")) { int trackNumber = Integer.parseInt(line.getOptionValue("s")); System.out.println(printAudioTrackSilenceDuration(videoFile, trackNumber, decibels, debug)); } else { printHelp(); } } else if (line.hasOption("-j")) { // choose file final JFileChooser fc = new JFileChooser(); fc.setVisible(true); int returnVal = fc.showOpenDialog(null); if (returnVal == JFileChooser.APPROVE_OPTION) { videoFile = fc.getSelectedFile().getAbsolutePath(); } else { return; } JTextArea tracks = new JTextArea(); tracks.setText(printAudioTracksList(videoFile, true)); JSpinner trackNumber = new JSpinner(); trackNumber.setValue(1); final JComponent[] inputs = new JComponent[] { new JLabel("Audio Tracks"), tracks, new JLabel("Track to analyze"), trackNumber }; JOptionPane.showMessageDialog(null, inputs, "Select Audio Track", JOptionPane.PLAIN_MESSAGE); JTextArea results = new JTextArea(); results.setText(printAudioTrackSilenceDuration(videoFile, (int) trackNumber.getValue(), decibels, false)); final JComponent[] resultsInputs = new JComponent[] { new JLabel("Results"), results }; JOptionPane.showMessageDialog(null, resultsInputs, "RESULTS!", JOptionPane.PLAIN_MESSAGE); } else { printHelp(); return; } } } catch (ParseException | IOException | InterruptedException exp) { // oops, something went wrong System.out.println("There was a problem :(\nReason: " + exp.getMessage()); } }
From source file:Main.java
public static void main(String[] args) { JPanel panel = new JPanel(new BorderLayout()); String[] values = new String[] { "One", "Two", "Three" }; JComboBox<String> comboBox = new JComboBox<>(values); panel.add(comboBox, BorderLayout.NORTH); JTextArea textArea = new JTextArea(2, 2); panel.add(textArea, BorderLayout.CENTER); JButton button = new JButton("Action"); button.addActionListener(new ActionListener() { @Override//from w w w.j av a2s. co m public void actionPerformed(ActionEvent e) { textArea.setText((String) comboBox.getSelectedItem()); comboBox.setSelectedIndex(0); } }); panel.add(button, BorderLayout.SOUTH); JFrame frame = new JFrame(); frame.add(panel); frame.pack(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); }
From source file:ThreadLister.java
/** * The main() method create a simple graphical user interface to display the * threads in. This allows us to see the "event dispatch thread" used by AWT * and Swing.// w ww .j a va 2s .c om */ public static void main(String[] args) { // Create a simple Swing GUI JFrame frame = new JFrame("ThreadLister Demo"); JTextArea textarea = new JTextArea(); frame.getContentPane().add(new JScrollPane(textarea), BorderLayout.CENTER); frame.setSize(500, 400); frame.setVisible(true); // Get the threadlisting as a string using a StringWriter stream StringWriter sout = new StringWriter(); // To capture the listing PrintWriter out = new PrintWriter(sout); ThreadLister.listAllThreads(out); // List threads to stream out.close(); String threadListing = sout.toString(); // Get listing as a string // Finally, display the thread listing in the GUI textarea.setText(threadListing); }
From source file:Main.java
public static void main(String[] args) { JTextArea area = new JTextArea(6, 32); Keymap parent = area.getKeymap(); Keymap newmap = JTextComponent.addKeymap("KeymapExampleMap", parent); KeyStroke u = KeyStroke.getKeyStroke(KeyEvent.VK_U, InputEvent.CTRL_MASK); Action actionU = new UppercaseAction(); newmap.addActionForKeyStroke(u, actionU); Action actionList[] = area.getActions(); Hashtable lookup = new Hashtable(); for (int j = 0; j < actionList.length; j += 1) lookup.put(actionList[j].getValue(Action.NAME), actionList[j]); KeyStroke L = KeyStroke.getKeyStroke(KeyEvent.VK_L, InputEvent.CTRL_MASK); Action actionL = (Action) lookup.get(DefaultEditorKit.selectLineAction); newmap.addActionForKeyStroke(L, actionL); area.setKeymap(newmap);// w w w.j a v a 2 s .c o m JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.add(new JScrollPane(area), BorderLayout.CENTER); area.setText("this is a test"); f.setSize(300, 300); f.setVisible(true); }
From source file:KeymapExample.java
public static void main(String[] args) { JTextArea area = new JTextArea(6, 32); Keymap parent = area.getKeymap(); Keymap newmap = JTextComponent.addKeymap("KeymapExampleMap", parent); KeyStroke u = KeyStroke.getKeyStroke(KeyEvent.VK_U, InputEvent.CTRL_MASK); Action actionU = new UpWord(); newmap.addActionForKeyStroke(u, actionU); Action actionList[] = area.getActions(); Hashtable lookup = new Hashtable(); for (int j = 0; j < actionList.length; j += 1) lookup.put(actionList[j].getValue(Action.NAME), actionList[j]); KeyStroke L = KeyStroke.getKeyStroke(KeyEvent.VK_L, InputEvent.CTRL_MASK); Action actionL = (Action) lookup.get(DefaultEditorKit.selectLineAction); newmap.addActionForKeyStroke(L, actionL); KeyStroke W = KeyStroke.getKeyStroke(KeyEvent.VK_W, InputEvent.CTRL_MASK); Action actionW = (Action) lookup.get(DefaultEditorKit.selectWordAction); newmap.addActionForKeyStroke(W, actionW); area.setKeymap(newmap);// ww w .j ava 2 s . com JFrame f = new JFrame("KeymapExample"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(new JScrollPane(area), BorderLayout.CENTER); area.setText("www.\n java2s \n .com."); f.pack(); f.setVisible(true); }