Results 1 to 2 of 2
  1. #1
    stevemcc is offline Member
    Join Date
    Feb 2008
    Posts
    7
    Rep Power
    0

    Default JLabel .setActionCommand

    I am making a chess board. Each space is represented by a JLabel. When the user clicks the JLabel, I would like to color the squares around it with the possible moves. This is done by one of my methods that is passed the x, y position of the piece on the space clicked. I figured I would do this by setting the .setActionCommand of each of to "00", "01", "02", etc. This way before I needed to pass they x and y, I could check the .setActionCommand value for the coords. Well, apparently, JLabels do not have this method like JButtons do. I see JLabels have .setActionMap, but I dont know this method is meant to work the same as .setActionCommand.

    So my question is, is there I was I can sort of 'mark' my JLabels with its coord so when it is clicked I can check it (many JLabels will use the same Listener)?

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    Try the Component method get/setName or the JComponent method get/setClientProperty.

Similar Threads

  1. JLabel append?
    By Jononomous in forum New To Java
    Replies: 0
    Last Post: 04-07-2008, 07:41 PM
  2. Problems with JLabel 2
    By geork in forum New To Java
    Replies: 2
    Last Post: 02-03-2008, 08:40 PM
  3. help me with JFrame and JLabel
    By michcio in forum New To Java
    Replies: 5
    Last Post: 11-20-2007, 07:44 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
  •