Results 1 to 3 of 3

Thread: JLabel

  1. #1
    Chris Walden is offline Developer On The Rise
    Join Date
    Feb 2014
    Location
    United States
    Posts
    3
    Rep Power
    0

    Default JLabel

    How do I make it to where i can click the JLabel and it will perform an action.

    Screenshot by Lightshot


    This is what I have so far

    Java Code:
    MouseEvents m1;
    
    public void menuItems() {
    	    window.add(l1 = new JLabel("Start"));
    	    l1.setForeground(Color.white);
    	    l1.setBounds(100, 100, 50, 50);
    	    l1.addMouseListener(m1);
    	    window.add(l2 = new JLabel("Help"));
    	    l2.setForeground(Color.white);
    	    l2.setBounds(160, 100, 50, 50);
    	    l2.addMouseListener(m1);
    	    window.add(l3 = new JLabel("Exit"));
    	    l3.setForeground(Color.white);	
    	    l3.setBounds(160, 160, 50, 50);
    	    l3.addMouseListener(m1);
    	}
    What do I do from here?

  2. #2
    pj6444 is offline Senior Member
    Join Date
    Jan 2013
    Posts
    164
    Rep Power
    2

    Default Re: JLabel

    You could just use a JButton and use ActionListeners instead.

  3. #3
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,616
    Rep Power
    5

    Default Re: JLabel

    And also, I recommend you avoid absolute positioning. Check out the use of Layout managers in the Oracle tutorials in my signature.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

Similar Threads

  1. Adding a JLabel to a JPanel - jlabel not showing
    By Bongeh in forum New To Java
    Replies: 17
    Last Post: 04-06-2010, 11:02 PM
  2. jLabel
    By Matty in forum AWT / Swing
    Replies: 3
    Last Post: 09-22-2008, 10:22 PM
  3. GUI - JLabel
    By Azndaddy in forum New To Java
    Replies: 8
    Last Post: 05-02-2008, 07:03 AM
  4. JLabel
    By Jack in forum AWT / Swing
    Replies: 2
    Last Post: 07-02-2007, 01:55 PM
  5. JLabel
    By Freddie in forum AWT / Swing
    Replies: 2
    Last Post: 05-29-2007, 02:19 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •