List of usage examples for javax.swing JTextArea JTextArea
public JTextArea()
From source file:Main.java
public Main() { setSize(300, 300);/* w ww.ja v a2 s.c o m*/ setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final JTextArea textArea = new JTextArea(); textArea.setText("Click Me!"); textArea.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (e.getButton() == MouseEvent.NOBUTTON) { textArea.setText("No button clicked..."); } else if (e.getButton() == MouseEvent.BUTTON1) { textArea.setText("Button 1 clicked..."); } else if (e.getButton() == MouseEvent.BUTTON2) { textArea.setText("Button 2 clicked..."); } else if (e.getButton() == MouseEvent.BUTTON3) { textArea.setText("Button 3 clicked..."); } System.out.println("Number of click: " + e.getClickCount()); System.out.println("Click position (X, Y): " + e.getX() + ", " + e.getY()); } }); getContentPane().add(textArea); }
From source file:Main.java
public Main() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(200, 200);//from w w w.j a v a 2 s . co m JTextArea textArea = new JTextArea(); textArea.addMouseWheelListener(new MouseWheelListener() { public void mouseWheelMoved(MouseWheelEvent e) { if (e.getWheelRotation() < 0) { System.out.println("Up... " + e.getWheelRotation()); } else { System.out.println("Down... " + e.getWheelRotation()); } System.out.println("ScrollAmount: " + e.getScrollAmount()); if (e.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL) { System.out.println("MouseWheelEvent.WHEEL_UNIT_SCROLL"); } if (e.getScrollType() == MouseWheelEvent.WHEEL_BLOCK_SCROLL) { System.out.println("MouseWheelEvent.WHEEL_BLOCK_SCROLL"); } } }); getContentPane().add(textArea); }
From source file:DropTest14.java
public DropTest14() { super("Drop Test 1.4"); setSize(300, 300);/*w w w .j a v a 2 s .c o m*/ setDefaultCloseOperation(EXIT_ON_CLOSE); getContentPane().add(new JLabel("Drop the choice from your JList here:"), BorderLayout.NORTH); ta = new JTextArea(); ta.setBackground(Color.white); getContentPane().add(ta, BorderLayout.CENTER); setVisible(true); }
From source file:Main.java
public Main() { super();//from www. j a va 2s. com this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); Container contentPane = this.getContentPane(); textArea = new JTextArea(); JScrollPane pane = new JScrollPane(textArea, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); contentPane.add(pane, BorderLayout.CENTER); }
From source file:Main.java
Main() { setSize(500, 300);//from w w w . j a v a 2 s . co m setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLayout(new BorderLayout()); JScrollPane pane = new JScrollPane(); txtMain = new JTextArea(); pane.setViewportView(txtMain); this.add(pane, BorderLayout.CENTER); JButton btnAddText = new JButton("Add Text"); btnAddText.addActionListener(e -> { txtMain.setText(txtMain.getText() + "\nLorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi sagittis id nibh vel rhoncus. "); String text = txtMain.getText(); txtMain.setCaretPosition(text != null ? text.length() : 0); }); add(btnAddText, BorderLayout.SOUTH); setVisible(true); }
From source file:Main.java
public Main(int axis) { super(BoxLayout.Y_AXIS); container = new Box(axis); container.setAlignmentX(Box.LEFT_ALIGNMENT); add(container);/*from w w w . j a v a2s.co m*/ JTextArea text = new JTextArea(); container.add(new JScrollPane(text)); JButton split = new JButton("Split"); split.setAlignmentX(Box.LEFT_ALIGNMENT); split.addActionListener(e -> { JTextArea t = new JTextArea(); container.add(new JScrollPane(t)); revalidate(); }); add(split); JButton axisChanger = new JButton("Change Axis"); axisChanger.setAlignmentX(Box.LEFT_ALIGNMENT); axisChanger.addActionListener(e -> { Box newContainer; if (((BoxLayout) container.getLayout()).getAxis() == BoxLayout.X_AXIS) { newContainer = Box.createVerticalBox(); } else { newContainer = Box.createHorizontalBox(); } for (Component c : container.getComponents()) { container.remove(c); newContainer.add(c); } remove(container); add(newContainer, 0); container = newContainer; container.setAlignmentX(Box.LEFT_ALIGNMENT); revalidate(); }); add(axisChanger); }
From source file:Main.java
private void addComponentsToPane() { display = new JTextArea(); display.setEditable(false);//from w w w . ja v a2 s . c o m JScrollPane scrollPane = new JScrollPane(display); scrollPane.setPreferredSize(new Dimension(500, 450)); getContentPane().add(scrollPane, BorderLayout.CENTER); addWindowFocusListener(this); }
From source file:DropTest.java
public DropTest() { super("Drop Test"); setSize(300, 300);/*from w ww .j ava 2 s.co m*/ getContentPane().add(new JLabel("Drop a list from your file chooser here:"), BorderLayout.NORTH); ta = new JTextArea(); ta.setBackground(Color.white); getContentPane().add(ta, BorderLayout.CENTER); // Set up our text area to recieve drops... // This class will handle drop events dt = new DropTarget(ta, this); setVisible(true); }
From source file:NewDropTest.java
public NewDropTest() { super("Drop Test"); setSize(300, 300);//from w w w . j a v a 2 s. c o m getContentPane().add(new JLabel("Drop a list from your file chooser here:"), BorderLayout.NORTH); ta = new JTextArea(); ta.setBackground(Color.white); getContentPane().add(ta, BorderLayout.CENTER); // Set up our text area to recieve drops... // This class will handle drop events // dt = new DropTarget(ta, this); setVisible(true); }
From source file:Main.java
private void addComponentsToPane() { JButton button = new JButton("Clear"); button.addActionListener(this); typingArea = new JTextField(20); typingArea.addKeyListener(this); displayArea = new JTextArea(); displayArea.setEditable(false);/*from ww w . jav a2 s . c om*/ JScrollPane scrollPane = new JScrollPane(displayArea); scrollPane.setPreferredSize(new Dimension(375, 125)); getContentPane().add(typingArea, BorderLayout.PAGE_START); getContentPane().add(scrollPane, BorderLayout.CENTER); getContentPane().add(button, BorderLayout.PAGE_END); }