Results 1 to 4 of 4
  1. #1
    SiX
    SiX is offline Member
    Join Date
    Jul 2011
    Posts
    24
    Rep Power
    0

    Default Add GCanvas to JButton?

    Hey everyone!

    I'm fairly new to java. I have only taken one class and am attempting to use the knowledge in building me a nice chess game.

    So far I have some nice JButtons that make my 8x8 grid, colored appropriately with white and black jpgs. The buttons are attached to actionCommands that give a strings based on location on the grid.

    I want the buttons color to remain static, adding the chess piece image (transparent background) on top of it. I don't know how to add multiple images to a JButton, if it's even possible. I thought about trying to add a GCanvas, such that I can layer the images one on top of the other.

    If I cannot do that with JButtons, can I do it by other means? Can I add actionEvents to things that are not JButtons? Like perhaps just a square shape? Or a jpg?

    Thanks!

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,331
    Rep Power
    25

    Default

    The buttons are attached to actionCommands that give a strings based on location on the grid.
    Another way to associate a "location" with a button would be to use the JComponent's ClientProperty attribute to save a Point object.

  3. #3
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,234
    Rep Power
    7

    Default

    I'm not sure why you need multiple images. Instead of using images to color the button you should just use setBackground(...). Then you add an image to represent the chess piece.

  4. #4
    SiX
    SiX is offline Member
    Join Date
    Jul 2011
    Posts
    24
    Rep Power
    0

    Default

    I was not aware that I could set background on a JButton, thanks for the heads up. I am interested in the previous comment about adding a location identifier to the variable. I shall give that a shot now :D

Similar Threads

  1. JButton help
    By ThrashingBoy in forum New To Java
    Replies: 8
    Last Post: 03-01-2011, 01:48 AM
  2. Regarding JButton
    By sneha_v27 in forum AWT / Swing
    Replies: 4
    Last Post: 02-18-2011, 02:17 PM
  3. JButton help
    By ThrashingBoy in forum New To Java
    Replies: 2
    Last Post: 01-29-2011, 12:39 PM
  4. JButton help :)
    By yasmin k in forum AWT / Swing
    Replies: 7
    Last Post: 11-12-2009, 09:53 PM
  5. Help with JButton
    By geoffreybarwise in forum New To Java
    Replies: 4
    Last Post: 05-21-2008, 10:48 AM

Posting Permissions

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