List of usage examples for javax.swing JTextArea JTextArea
public JTextArea(int rows, int columns)
From source file:Main.java
public static void main(String[] args) { JFrame f = new JFrame(); JTextArea ta = new JTextArea(5, 32); ta.setText("That's one small step for man...\nOne giant leap for mankind."); ta.setSelectionStart(10);/*w w w . ja v a2 s .c o m*/ ta.setSelectionEnd(20); f.getContentPane().add(ta); f.setSize(100, 100); f.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JTextArea area = new JTextArea(5, 20); area.setText("this is a test."); String charsToHighlight = "aeiouAEIOU"; Highlighter h = area.getHighlighter(); h.removeAllHighlights();/*ww w .j a va 2 s . c o m*/ String text = area.getText().toUpperCase(); for (int i = 0; i < text.length(); i += 1) { char ch = text.charAt(i); if (charsToHighlight.indexOf(ch) >= 0) try { h.addHighlight(i, i + 1, DefaultHighlighter.DefaultPainter); } catch (Exception ble) { } } }
From source file:Main.java
public static void main(String[] args) { JFrame f = new JFrame(); JTextArea ta = new JTextArea(5, 32); ta.setText("That's one small step for man...\nOne giant leap for mankind."); ta.setLineWrap(true);//from w w w . j a v a 2s. com ta.setWrapStyleWord(true); f.getContentPane().add(ta); f.setSize(100, 100); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame f = new JFrame(); JTextArea ta = new JTextArea(5, 32); ta.setText("That's one small step for man...\nOne giant leap for mankind."); ta.setLineWrap(true);//from ww w .ja va 2 s .c o m ta.setWrapStyleWord(true); f.getContentPane().add(ta); f.setSize(100, 100); f.setVisible(true); ((AbstractDocument) ta.getDocument()).dump(System.out); }
From source file:Main.java
public static void main(String[] args) { JTextArea textArea = new JTextArea(5, 30); textArea.setOpaque(false);/*from ww w .jav a 2 s .c om*/ JViewport viewport = new JViewport() { @Override protected void paintComponent(Graphics g) { super.paintComponent(g); int w = this.getWidth(); int h = this.getHeight(); g.setColor(Color.RED); g.fillRect(0, 0, w / 2, h / 2); } }; JScrollPane scrollPane = new JScrollPane(); scrollPane.setViewport(viewport); scrollPane.setViewportView(textArea); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(scrollPane); frame.setLocationByPlatform(true); frame.pack(); frame.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);/* w w w. j av a 2 s.c o m*/ 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); }
From source file:Main.java
public static void main(String[] args) { JFrame window = new JFrame(); window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); window.setResizable(false);/*from www .j av a2s. c om*/ JTextArea textArea = new JTextArea(25, 30); JScrollPane textScroll = new JScrollPane(textArea, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); window.add(textScroll); window.pack(); window.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JTextArea ta = new JTextArea(20, 20); ((AbstractDocument) ta.getDocument()).setDocumentFilter(new MyFilter()); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new BorderLayout()); frame.add(new JScrollPane(ta)); frame.pack();/*from ww w. ja v a2 s . c o m*/ frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) throws Exception { JFrame frame = new JFrame("MultiHighlight"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextArea comp = new JTextArea(5, 20); comp.setText("this is a test"); frame.getContentPane().add(new JScrollPane(comp), BorderLayout.CENTER); String charsToHighlight = "a"; Highlighter h = comp.getHighlighter(); h.removeAllHighlights();/* www . j a va2 s. c o m*/ String text = comp.getText().toUpperCase(); for (int j = 0; j < text.length(); j += 1) { char ch = text.charAt(j); if (charsToHighlight.indexOf(ch) >= 0) h.addHighlight(j, j + 1, DefaultHighlighter.DefaultPainter); } frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JTextArea textArea = new JTextArea(10, 30); AbstractDocument doc = (AbstractDocument) textArea.getDocument(); doc.setDocumentFilter(new EndOfLineFilter()); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(new JScrollPane(textArea)); frame.pack();//from w ww .jav a 2s.c om frame.setVisible(true); }