List of usage examples for javax.swing JTextArea JTextArea
public JTextArea()
From source file:JDK6TextComponentDemo.java
public static void main(String[] args) throws Exception { final JTextArea textArea = new JTextArea(); textArea.setText("text"); JScrollPane jScrollPane = new JScrollPane(textArea); final MessageFormat header = new MessageFormat("My Header"); final MessageFormat footer = new MessageFormat("My Footer"); JPanel contentPane = new JPanel(); contentPane.setLayout(new BorderLayout()); contentPane.add(jScrollPane, BorderLayout.CENTER); JFrame frame = new JFrame(); frame.setTitle("Text-component Printing Demo"); frame.setSize(400, 200);/* ww w. j av a 2 s .c o m*/ frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setContentPane(contentPane); frame.setVisible(true); textArea.print(header, footer, true, null, null, true); }
From source file:Main.java
public static void main(String[] argv) throws Exception { JTextArea component = new JTextArea(); Action defAction = findDefaultAction(component); component.getKeymap().setDefaultAction(new MyDefaultAction(defAction)); }
From source file:TextArea.java
public static void main(String[] args) { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextArea area = new JTextArea(); area.setLineWrap(true);//from w w w .j ava 2 s. c o m area.setWrapStyleWord(true); area.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8)); f.add(new JScrollPane(area)); f.setSize(new Dimension(350, 300)); f.setLocationRelativeTo(null); f.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame(); Container content = frame.getContentPane(); content.setLayout(new GridLayout(0, 2)); JTextArea leftTextArea = new JTextArea(); content.add(leftTextArea);// ww w . j a v a 2 s . c o m leftTextArea.paste(); frame.setSize(250, 150); frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextArea textarea1 = new JTextArea(); Document document = textarea1.getDocument(); JTextArea textarea2 = new JTextArea(document); JTextArea textarea3 = new JTextArea(document); frame.setLayout(new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS)); frame.add(new JScrollPane(textarea1)); frame.add(new JScrollPane(textarea2)); frame.add(new JScrollPane(textarea3)); frame.setSize(300, 400);/*ww w. ja v a2s . c o m*/ frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { DocumentFilter dfilter = new UpperCaseFilter(); JTextArea jta = new JTextArea(); ((AbstractDocument) jta.getDocument()).setDocumentFilter(dfilter); JFrame frame = new JFrame("UpcaseFilter"); frame.getContentPane().add(jta, java.awt.BorderLayout.CENTER); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(200, 120);/* ww w . j a v a2 s . c o m*/ frame.setVisible(true); }
From source file:Main.java
public static void main(String[] argv) throws Exception { JTextArea textComp = new JTextArea(); Highlighter hilite = textComp.getHighlighter(); Highlighter.Highlight[] hilites = hilite.getHighlights(); for (int i = 0; i < hilites.length; i++) { if (hilites[i].getPainter() instanceof MyHighlightPainter) { hilite.removeHighlight(hilites[i]); }/*from www .j a va 2 s . c om*/ } highlight(textComp); }
From source file:Main.java
public static void main(String[] argv) { InputMap im = new JTextArea().getInputMap(JComponent.WHEN_FOCUSED); im.put(KeyStroke.getKeyStroke("F2"), "actionName"); ActionMap am = new JTextArea().getActionMap(); am.put("actionName", new AbstractAction("actionName") { public void actionPerformed(ActionEvent evt) { System.out.println((JTextComponent) evt.getSource()); }//from w ww . jav a 2 s. c om }); im.put(KeyStroke.getKeyStroke("F3"), "actionName2"); am.put("actionName2", new AbstractAction("actionName2") { public void actionPerformed(ActionEvent evt) { System.out.println((JTextComponent) evt.getSource()); } }); JButton component1 = new JButton("button 1"); JButton component2 = new JButton("button 2"); component1.setInputMap(JComponent.WHEN_FOCUSED, im); component2.setInputMap(JComponent.WHEN_FOCUSED, im); component1.setActionMap(am); component2.setActionMap(am); }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame("Caret Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextArea textArea = new JTextArea(); JScrollPane scrollPane = new JScrollPane(textArea); frame.add(scrollPane, BorderLayout.CENTER); CaretListener listener = new CaretListener() { public void caretUpdate(CaretEvent caretEvent) { System.out.println("Dot: " + caretEvent.getDot()); System.out.println("Mark: " + caretEvent.getMark()); }//from w ww .ja v a 2 s. c o m }; textArea.addCaretListener(listener); frame.setSize(250, 150); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] argv) throws Exception { JTextArea comp = new JTextArea(); String actionName = "Lowercase"; JFrame f = new JFrame(); f.add(new JScrollPane(comp)); f.setSize(300, 300);/*from w w w.jav a 2 s .co m*/ f.setVisible(true); comp.getInputMap().put(KeyStroke.getKeyStroke("F2"), actionName); comp.getActionMap().put(actionName, new TextAction(actionName) { public void actionPerformed(ActionEvent evt) { JTextComponent comp = getTextComponent(evt); if (comp.getSelectionStart() == comp.getSelectionEnd()) { if (comp.getCaretPosition() < comp.getDocument().getLength()) { try { int pos = comp.getCaretPosition(); Document doc = comp.getDocument(); String str = doc.getText(pos, 1).toLowerCase(); doc.remove(pos, 1); doc.insertString(pos, str, null); comp.moveCaretPosition(pos + 1); } catch (Exception e) { System.out.println(); } } } else { int s = comp.getSelectionStart(); int e = comp.getSelectionEnd(); comp.replaceSelection(comp.getSelectedText().toLowerCase()); comp.select(s, e); } } }); }