Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to find which panel a component belongs to?
    text
    copied!<p>I need a hand with something.</p> <p>I got a panel, which I'm filling with Objects. These objects each create a panel inside the panel, which is filled with labels. It's a homemade JTable so to speak. Now I need to make a right-click menu, where I click edit/delete/etc. which needs to know what Object I clicked on.</p> <pre><code>public class Aktivitet { static JPanel sPanel; static String navn; static String kontakt; static String event; static String oprettet; static String note; static String deadline; static int tilstand; public Aktivitet(JPanel panel, String sNavn, String sKontakt, String sEvent, String sOprettet, String sNote, String sDeadline, int sTilstand) { this.navn = sNavn; this.kontakt = sKontakt; this.event = sEvent; this.oprettet = sOprettet; this.note = sNote; this.deadline = sDeadline; this.tilstand = sTilstand; this.sPanel = panel; JPanel akPan = new JPanel(); JPanel fillerPanel = new JPanel(); if (tilstand == 0) akPan.setBackground(Color.GREEN); if (tilstand == 1) akPan.setBackground(Color.YELLOW); if (tilstand == 2) akPan.setBackground(Color.RED); akPan.setLayout(new GridLayout(4,3)); akPan.setBorder(BorderFactory.createRaisedBevelBorder()); akPan.setSize(new Dimension(10000, 75)); akPan.setMaximumSize(new Dimension(10000, 75)); fillerPanel.setBorder(BorderFactory.createLineBorder(Color.DARK_GRAY)); fillerPanel.setSize(new Dimension(10000, 1)); fillerPanel.setMaximumSize(new Dimension(10000, 1)); JLabel navnP = new JLabel(); JLabel kontaktP = new JLabel(); JLabel eventP = new JLabel(); JLabel oprettetP = new JLabel(); JLabel noteP = new JLabel(); JLabel deadlineP = new JLabel(); JLabel label_navn = new JLabel(); JLabel label_kontakt = new JLabel(); JLabel label_event = new JLabel(); JLabel label_oprettet = new JLabel(); JLabel label_note = new JLabel(); JLabel label_deadline = new JLabel(); navnP.setText("Aktivitetsnavn:"); navnP.setFont(new Font("dialog",Font.ITALIC,9)); kontaktP.setText("Kontaktperson:"); kontaktP.setFont(new Font("dialog",Font.ITALIC,9)); eventP.setText("Event:"); eventP.setFont(new Font("dialog",Font.ITALIC,9)); label_navn.setText(navn); label_navn.setFont(new Font("monospaced",Font.BOLD,16)); label_kontakt.setText(kontakt); label_kontakt.setFont(new Font("monospaced",Font.BOLD,16)); label_event.setText(event); label_event.setFont(new Font("monospaced",Font.BOLD,16)); oprettetP.setText("Oprettet:"); oprettetP.setFont(new Font("dialog",Font.ITALIC,9)); noteP.setText("Evt. Note:"); noteP.setFont(new Font("dialog",Font.ITALIC,9)); deadlineP.setText("Deadline:"); deadlineP.setFont(new Font("dialog",Font.ITALIC,9)); label_oprettet.setText(oprettet); label_oprettet.setFont(new Font("monospaced",Font.BOLD,16)); label_note.setText(note); label_note.setFont(new Font("monospaced",Font.BOLD,16)); label_deadline.setText(deadline); label_deadline.setFont(new Font("monospaced",Font.BOLD,16)); akPan.add(navnP); akPan.add(kontaktP); akPan.add(eventP); akPan.add(label_navn); akPan.add(label_kontakt); akPan.add(label_event); akPan.add(oprettetP); akPan.add(noteP); akPan.add(deadlineP); akPan.add(label_oprettet); akPan.add(label_note); akPan.add(label_deadline); panel.add(akPan); panel.add(fillerPanel); panel.addMouseListener(new MouseActionListener()); akPan.setVisible(true); fillerPanel.setVisible(true); } public class MouseActionListener implements MouseListener { public void mouseClicked(MouseEvent e) { } public void mousePressed(MouseEvent e) { } public void mouseReleased(MouseEvent e) { } public void mouseEntered(MouseEvent e) { } public void mouseExited(MouseEvent e) { } } } </code></pre> <p>Thanks a lot!</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