List of usage examples for javax.swing JTextArea JTextArea
public JTextArea()
From source file:ActionsMenuBar.java
public static void main(String args[]) { final JFrame frame = new JFrame("TextAction Usage"); Container contentPane = frame.getContentPane(); final JScrollPane scrollPane = new JScrollPane(); contentPane.add(scrollPane, BorderLayout.CENTER); final JMenuBar menuBar = new JMenuBar(); frame.setJMenuBar(menuBar);/*from ww w .jav a 2s . c om*/ ActionListener actionListener = new ActionListener() { JTextComponent component; public void actionPerformed(ActionEvent actionEvent) { // Determine which component selected String command = actionEvent.getActionCommand(); if (command.equals("JTextField")) { component = new JTextField(); } else if (command.equals("JPasswordField")) { component = new JPasswordField(); } else if (command.equals("JTextArea")) { component = new JTextArea(); } else if (command.equals("JTextPane")) { component = new JTextPane(); } else { component = new JEditorPane(); } scrollPane.setViewportView(component); // Process action list Action actions[] = component.getActions(); menuBar.removeAll(); menuBar.revalidate(); JMenu menu = null; for (int i = 0, n = actions.length; i < n; i++) { if ((i % 10) == 0) { menu = new JMenu("From " + i); menuBar.add(menu); } menu.add(actions[i]); } menuBar.revalidate(); } }; String components[] = { "JTextField", "JPasswordField", "JTextArea", "JTextPane", "JEditorPane" }; final Container componentsContainer = RadioButtonUtils.createRadioButtonGrouping(components, "Pick to List Actions", actionListener); contentPane.add(componentsContainer, BorderLayout.WEST); frame.setSize(400, 300); frame.setVisible(true); }
From source file:UndoExample1.java
public static void main(String[] args) { try {/*from w w w.j ava 2 s.c om*/ UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); } catch (Exception evt) { } JFrame f = new UndoExample1(); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent evt) { System.exit(0); } }); f.setSize(250, 300); f.setVisible(true); // Create and show a frame monitoring undoable edits JFrame undoMonitor = new JFrame("Undo Monitor"); final JTextArea textArea = new JTextArea(); textArea.setEditable(false); undoMonitor.getContentPane().add(new JScrollPane(textArea)); undoMonitor.setBounds(f.getLocation().x + f.getSize().width, f.getLocation().y, 400, 200); undoMonitor.setVisible(true); pane.getDocument().addUndoableEditListener(new UndoableEditListener() { public void undoableEditHappened(UndoableEditEvent evt) { UndoableEdit edit = evt.getEdit(); textArea.append(edit.getPresentationName() + "(" + edit.toString() + ")\n"); } }); // Create and show a frame monitoring document edits JFrame editMonitor = new JFrame("Edit Monitor"); final JTextArea textArea2 = new JTextArea(); textArea2.setEditable(false); editMonitor.getContentPane().add(new JScrollPane(textArea2)); editMonitor.setBounds(undoMonitor.getLocation().x, undoMonitor.getLocation().y + undoMonitor.getSize().height, 400, 200); editMonitor.setVisible(true); pane.getDocument().addDocumentListener(new DocumentListener() { public void changedUpdate(DocumentEvent evt) { textArea2.append("Attribute change\n"); } public void insertUpdate(DocumentEvent evt) { textArea2.append("Text insertion\n"); } public void removeUpdate(DocumentEvent evt) { textArea2.append("Text removal\n"); } }); }
From source file:SwingToolBarSample.java
public static void main(String args[]) { ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { System.out.println(actionEvent.getActionCommand()); }//from ww w. j av a 2 s .c o m }; JFrame frame = new JFrame("JToolBar Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JToolBar toolbar = new JToolBar(); toolbar.putClientProperty("JToolBar.isRollover", Boolean.TRUE); for (int i = 0, n = buttonColors.length; i < n; i++) { Object color[] = buttonColors[i]; if (color == null) { toolbar.addSeparator(); } else { Icon icon = new DiamondIcon((Color) color[COLOR_POSITION], true, 20, 20); JButton button = new JButton(icon); button.setActionCommand((String) color[STRING_POSITION]); button.addActionListener(actionListener); toolbar.add(button); } } Action action = new ActionMenuSample.ShowAction(frame); toolbar.add(action); Container contentPane = frame.getContentPane(); contentPane.add(toolbar, BorderLayout.NORTH); JTextArea textArea = new JTextArea(); JScrollPane pane = new JScrollPane(textArea); contentPane.add(pane, BorderLayout.CENTER); frame.setSize(350, 150); 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.//from ww w .j av a2 s . com */ 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:UndoManagerHelper.java
public static void main(String args[]) { JFrame frame = new JFrame("Undo Sample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextArea textArea = new JTextArea(); JScrollPane scrollPane = new JScrollPane(textArea); UndoManager manager = new UndoManager(); textArea.getDocument().addUndoableEditListener(manager); JToolBar toolbar = new JToolBar(); JButton undoButton = new JButton(UndoManagerHelper.getUndoAction(manager)); toolbar.add(undoButton);/* ww w . j a va 2s. c o m*/ JButton redoButton = new JButton(UndoManagerHelper.getRedoAction(manager)); toolbar.add(redoButton); frame.add(toolbar, BorderLayout.NORTH); frame.add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150); 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 ww w .j a v a 2s .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:UndoExample5.java
public static void main(String[] args) { try {//from w ww . j av a2s .co m UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); } catch (Exception evt) { } JFrame f = new UndoExample5(); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent evt) { System.exit(0); } }); f.setSize(250, 300); f.setVisible(true); // Create and show a frame monitoring undoable edits JFrame undoMonitor = new JFrame("Undo Monitor"); final JTextArea textArea = new JTextArea(); textArea.setEditable(false); undoMonitor.getContentPane().add(new JScrollPane(textArea)); undoMonitor.setBounds(f.getLocation().x + f.getSize().width, f.getLocation().y, 400, 200); undoMonitor.setVisible(true); pane.getDocument().addUndoableEditListener(new UndoableEditListener() { public void undoableEditHappened(UndoableEditEvent evt) { UndoableEdit edit = evt.getEdit(); textArea.append(edit.getPresentationName() + "(" + edit.toString() + ")\n"); } }); // Create and show a frame monitoring document edits JFrame editMonitor = new JFrame("Edit Monitor"); final JTextArea textArea2 = new JTextArea(); textArea2.setEditable(false); editMonitor.getContentPane().add(new JScrollPane(textArea2)); editMonitor.setBounds(undoMonitor.getLocation().x, undoMonitor.getLocation().y + undoMonitor.getSize().height, 400, 200); editMonitor.setVisible(true); pane.getDocument().addDocumentListener(new DocumentListener() { public void changedUpdate(DocumentEvent evt) { textArea2.append("Attribute change\n"); } public void insertUpdate(DocumentEvent evt) { textArea2.append("Text insertion\n"); } public void removeUpdate(DocumentEvent evt) { textArea2.append("Text removal\n"); } }); }
From source file:FileTransferHandler.java
/** * This class demonstrates the FileTransferHandler by installing it on a * JTextArea component and providing a JFileChooser to drag and cut files. */// w w w .ja va 2 s .c o m public static void main(String[] args) { // Here's the text area. Note how we wrap our TransferHandler // around the default handler returned by getTransferHandler() JTextArea textarea = new JTextArea(); TransferHandler defaultHandler = textarea.getTransferHandler(); textarea.setTransferHandler(new FileTransferHandler(defaultHandler)); // Here's a JFileChooser, with dragging explicitly enabled. JFileChooser filechooser = new JFileChooser(); filechooser.setDragEnabled(true); // Display them both in a window JFrame f = new JFrame("File Transfer Handler Test"); f.getContentPane().add(new JScrollPane(textarea), "Center"); f.getContentPane().add(filechooser, "South"); f.setSize(400, 600); f.setVisible(true); }
From source file:Main.java
public static JTextArea newJTextArea() { JTextArea ret = new JTextArea(); Insets insets = new Insets(4, 4, 4, 4); ret.setMargin(insets);// www. j a v a 2 s. c o m // ret.setHorizontalAlignment(SwingConstants.RIGHT); return ret; }
From source file:MetalModExample.java
public static JComponent makeExamplePane() { JTextArea text = new JTextArea(); try {//from w w w. j a v a 2 s. c om text.read(new FileReader("MetalModExample.java"), null); } catch (IOException ex) { } JScrollPane scroll = new JScrollPane(text); return scroll; }