> I am new to the GUI fundamentals of Java. Could you tell me how to add
> JCheckBox as a MenuItem?
[quoted text clipped - 4 lines]
> Regards,
> Ankur
Thanx Vova. By being new, I meant, I am not very well conversant with
specific details of GUI API's as in, in the ocean of API's of java,
where one has to really search, I am googling in order to search it
faster.
And Thomas, thanx to you too. I am in the process of trying JCheckBox
out.
here is a snippet of the code. My problem is, the check-boxes are not
getting editted, as in, checked. I've added mouseListener, still.
Please tell me how to go about it.
**************************
class MyPopupMenu extends JPopupMenu implements MouseListener
{
public MouseListener ml;
public MyPopupMenu(Vector columns)
{
super();
System.out.println("Inside MyPopupMenu Constructor, Size :
"+columns.size());
System.out.println((String)columns.elementAt(0));
JCheckBoxMenuItem[] item = new JCheckBoxMenuItem[columns.size()];
for(int i =0;i<columns.size();i++)
{
item[i] = new JCheckBoxMenuItem((String)columns.elementAt(i));
item[i].addMouseListener(ml);
add(item[i]);
}
}
public void mousePressed(MouseEvent evt)
{
// if (evt.isPopupTrigger()) {
System.out.println("Ankur :
"+(String)((Object)(evt.getComponent()).getClass()));
show(evt.getComponent(), evt.getX(), evt.getY());
//}
}
public void mouseReleased(MouseEvent evt)
{
System.out.println(" ");
if (evt.isPopupTrigger()) {
show(evt.getComponent(), evt.getX(), evt.getY());
}
}
public void mouseClicked(MouseEvent evt){System.out.println("Ankur :
"+(String)((Object)(evt.getComponent()).getClass()));}
public void mouseEntered(MouseEvent evt){System.out.println("Ankur :
"+(String)((Object)(evt.getComponent()).getClass()));}
public void mouseExited(MouseEvent evt){System.out.println("Ankur :
"+(String)((Object)(evt.getComponent()).getClass()));}
****************************************
last 3 method's i have just filled some code to check if control goes
there...
alas, it isn't...
Do you have any idea how to do event-handling of the
checkboxesMenuItems??
Regards,
Ankur
Thomas Fritsch - 13 Apr 2006 10:27 GMT
> here is a snippet of the code. My problem is, the check-boxes are not
> getting editted, as in, checked. I've added mouseListener, still.
> Please tell me how to go about it.
>
> **************************
> class MyPopupMenu extends JPopupMenu implements MouseListener
[...]
> {
> ****************************************
[quoted text clipped - 5 lines]
> Do you have any idea how to do event-handling of the
> checkboxesMenuItems??
I think the MouseListener approach is the wrong one (despite that you
forgot to call to addMouseListener(...)).
Use ActionListener instead, and don't forget to call
menuItem.addActionListener(...);
An example about event-handling for menu items in general (not only
JCheckBoxMenuitem) is given in
<http://java.sun.com/docs/books/tutorial/uiswing/components/menu.html#event>.
(By the way: It is the same tutorial page I gave you in my first answer)

Signature
"Thomas:Fritsch$ops:de".replace(':','.').replace('$','@')