> doesnt work
the way you are doing it doesn't work.
the textArea requires focus for the selection highlight to be visible.
if you are (e.g.) clicking a button for your selectAll(), the button gets the focus.
click the button, then tab into the textArea (note: tab, not click into).
after tabbing, if you now see the selection highlight, add this line
JTextAreaName.requestFocusInWindow();//<-
JTextAreaName.selectAll();
public class Myprogram extends JFrame
{
public Classname()
{
JMenuJMenuName= new JMenu("JMenuName");
JMenuItem JMenuItemName=new JMenuItem("Select all");
JMenuName.add(JMenuItemName);
JMenuItemName.addActionListener(new SelectAllAction());
class SelectAllAction implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
TArea.requestFocusInWindow();
TArea.selectAll();
}
}
}
}
note that i didnt include the menubar declaration here ,
the main problem is thatt after i click the JMenuItemName which call the SelectAllAction class, nothing happeens
everything include the TArea has been added to the container and i can see it on screen, i have only 1 textarea
Message was edited by:
w32sysfie
worked OK for me
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class Myprogram extends JFrame
{
JTextArea TArea = new JTextArea(10,10);
public Myprogram()
{
JMenu JMenuName= new JMenu("JMenuName");
JMenuItem JMenuItemName=new JMenuItem("Select all");
JMenuName.add(JMenuItemName);
JMenuItemName.addActionListener(new SelectAllAction());
getContentPane().add(new JScrollPane(TArea));
JMenuBar mb = new JMenuBar();
mb.add(JMenuName);
setJMenuBar(mb);
pack();
setLocationRelativeTo(null);
setVisible(true);
}
class SelectAllAction implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
TArea.requestFocusInWindow();
TArea.selectAll();
}
}
public static void main(String[] args){new Myprogram();}
}