Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to access object created in serialized way?
    text
    copied!<p>This is my code: where i click the right button of mouse, and select test1 the code create a JLabel and put it in that position.</p> <pre><code> public class Test extends JFrame { int x; int y; JPopupMenu menu = new JPopupMenu("Popup"); class MyLabel extends JLabel { public MyLabel(String text) { super(text); addMouseListener(new PopupTriggerListener()); } class PopupTriggerListener extends MouseAdapter { public void mousePressed(MouseEvent ev) { if (ev.isPopupTrigger()) { menu.show(ev.getComponent(), ev.getX(), ev.getY()); x = ev.getX(); y = ev.getY(); } } public void mouseReleased(MouseEvent ev) { if (ev.isPopupTrigger()) { menu.show(ev.getComponent(), ev.getX(), ev.getY()); x = ev.getX(); y = ev.getY(); } } public void mouseClicked(MouseEvent ev) { } } } JLabel label = new MyLabel("right-click"); public Test() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JMenuItem item = new JMenuItem("Test1"); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("Menu item Test1"); JLabel newLabel = new JLabel("test"); label.add(newLabel); newLabel.setBounds(x, y, 40, 10); } }); menu.add(item); item = new JMenuItem("Test2"); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("Menu item Test2"); } }); menu.add(item); getContentPane().add(label); pack(); setSize(300, 100); } public static void main(String[] args) { new Test().setVisible(true); } </code></pre> <p>But i don't know after, how i can access that labels (ex to modify their text). I want also to can delete that labels once created if the user click on it with the right button and select "delete", but in the actionPerformed code netbeans don't let me add another actionListener.. Anyone can help me? Thanks</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload