Results 1 to 3 of 3
- 05-28-2007, 11:16 AM #1
Member
- Join Date
- May 2007
- Posts
- 10
- Rep Power
- 0
- 05-28-2007, 11:19 AM #2
Member
- Join Date
- May 2007
- Posts
- 6
- Rep Power
- 0
Hi Valeriano,
Please try the following code:
Java Code:import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.text.*; public class TextAreaSelectLine extends JFrame implements MouseListener { JTextArea textArea; Action selectLine; public TextAreaSelectLine() { textArea = new JTextArea( "one two\nthree four", 10, 30 ); textArea.addMouseListener( this ); JScrollPane scrollPane = new JScrollPane( textArea ); getContentPane().add( scrollPane, BorderLayout.SOUTH ); getContentPane().add( new JTextArea() ); selectLine = getAction(DefaultEditorKit.selectLineAction); } private Action getAction(String name) { Action action = null; Action[] actions = textArea.getActions(); for (int i = 0; i < actions.length; i++) { if (name.equals( actions[i].getValue(Action.NAME).toString() ) ) { action = actions[i]; break; } } return action; } public void mouseClicked(MouseEvent e) { if ( SwingUtilities.isLeftMouseButton(e) && e.getClickCount() == 1) { selectLine.actionPerformed( null ); } } public void mousePressed(MouseEvent e) {} public void mouseReleased(MouseEvent e) {} public void mouseEntered(MouseEvent e) {} public void mouseExited(MouseEvent e) {} public static void main(String[] args) { TextAreaSelectLine frame = new TextAreaSelectLine(); frame.setDefaultCloseOperation( EXIT_ON_CLOSE ); frame.pack(); frame.setVisible(true); } }
- 05-28-2007, 11:20 AM #3
Member
- Join Date
- May 2007
- Posts
- 10
- Rep Power
- 0
Similar Threads
-
Select Count
By Apple2 in forum JavaServer Pages (JSP) and JSTLReplies: 1Last Post: 04-29-2008, 09:02 AM -
How to synchronize blocks instead of entire methods
By Java Tip in forum java.langReplies: 0Last Post: 04-09-2008, 06:39 PM -
Select specific cell
By Echilon in forum New To JavaReplies: 1Last Post: 01-01-2008, 07:47 AM -
Adding custom highlight to JEditorPane
By andrewb in forum AWT / SwingReplies: 0Last Post: 06-22-2007, 06:48 PM -
GNU Source-highlight 2.7
By levent in forum Java SoftwareReplies: 0Last Post: 06-12-2007, 08:39 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks