Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6564435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:57:58+00:00 2026-05-25T13:57:58+00:00

I need a hand with something. I got a panel, which I’m filling with

  • 0

I need a hand with something.

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.

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) {
    }
}

}

Thanks a lot!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T13:57:58+00:00Added an answer on May 25, 2026 at 1:57 pm

    You can use retrieve the source component that generated the event from the MouseEvent itself:

    public void mouseClicked(MouseEvent e) {
         Object o = e.getSource();
    }
    

    You should use instanceof to check the source type and cast the object to it:

    if (o instanceof JLabel){
        JLabel label = (JLabel)o;
    }else if (o instanceof JPanel){
        JPanel panel = (JPanel)o;
    }
    

    In order to discriminate between different components of the same type you could add a property to them with putClientProperty() method, and then retrieve it:

    JLabel label = new JLabel();
    label.putClientProperty("id", new Integer(10));
    

    then from inside the event handler retrieve the property:

    if (o instanceof JLabel){
        JLabel label = (JLabel)o;
        Integer labelId = (Integer)label.getClientProperty("id");
    }
    

    You can use getParent() method on a component to find it’s parent and so on…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating a card game in Silverlight. Each player has a Hand which
Need a hand/guide of creating a view that handles a list of parameters which
I need a quick hand figuring out what this code is doing, and how
I am stuck and in need of a hand. Hope someone can help? Anyone
I need to get the left hand side integer value from a decimal or
I have following array, that I need to operate by hand on bitmaps. const
I know I wouldn't need this with Typemock, however, with something like MoQ ,
I've got a comma delimited string of id's coming in and I need some
I'm clearly missing something here. I need to fill methods of dynamic AS3 class
I got a trouble using GMAP V3, when I realized that I need to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.