Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: JButton Image does not show. on background image.

  1. #1
    Junior Member
    Join Date
    Feb 2014
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default JButton Image does not show. on background image.

    I am very new to Java. I successfully added a background image on the Panel but I can't create my JButton image on top of my background image. Can someone help advise. Thanks.

    ImageIcon piano = new ImageIcon("src/img/piano_backgrd.png");
    JLabel backlabel = new JLabel(piano);
    panel.add(backlabel, new Integer(Integer.MIN_VALUE));
    backlabel.setBounds(0, 0, piano.getIconWidth(), piano.getIconHeight());
     
    JButton volup = new JButton(new ImageIcon("src/img/volup.png"));
    volup.setLocation(10, 0);
    panel.add(volup);


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,151
    My Mood
    Mellow
    Thanks
    187
    Thanked 660 Times in 647 Posts

    Default Re: JButton Image does not show. on background image.

    Welcome to the forum! Please read this topic to learn how to post code in code or highlight tags and other useful info for newcomers.

    This could be Java (!= JavaScript). Which language are you using?

  3. #3
    Junior Member
    Join Date
    Feb 2014
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: JButton Image does not show. on background image.

    Oh I thought its the same. I wrote the script in NetBeans.

  4. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,151
    My Mood
    Mellow
    Thanks
    187
    Thanked 660 Times in 647 Posts

    Default Re: JButton Image does not show. on background image.

    Java is not a scripted language. Java source code is compiled into .class files and then run on the Java Virtual Machine.

    Netbeans is a fancy editor, also known as an Integrated Development Environment or IDE. Since I don't think Netbeans does JavaScript (it may, but I don't use it), and the little bit of code you posted looks like Java, I think you may be writing Java source code, not JavaScript.

    Are you using the graphical GUIBuilder or writing the GUI code 'by hand'?

  5. #5
    Junior Member
    Join Date
    Feb 2014
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: JButton Image does not show. on background image.

    Oh ok now I understand.

    I am not using the GUIBuilder, I am writing the code 'by hand'.

  6. #6
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,151
    My Mood
    Mellow
    Thanks
    187
    Thanked 660 Times in 647 Posts

    Default Re: JButton Image does not show. on background image.

    So you have GUI/OOP experience in another language? Which one? If not, why are you trying to learn programming (or Java) by starting with the more advanced topics/projects?

    As for your specific question, what you're trying to do is not entirely clear. What do you mean by "on top of?" It is possible to create a watermark effect, if that's what you're trying to do. Search for that, and you'll find suggested approaches. But in general, two components in a container cannot occupy the same place at the same time.

  7. #7
    Junior Member
    Join Date
    Feb 2014
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: JButton Image does not show. on background image.

    Thanks for replying, I have found ways to solve this problem.

Similar Threads

  1. A Background Image
    By Randor in forum AWT / Java Swing
    Replies: 6
    Last Post: November 14th, 2012, 04:28 PM
  2. Replies: 1
    Last Post: August 4th, 2012, 10:02 AM
  3. Cant get background image to take up whole panel
    By Lanuk in forum AWT / Java Swing
    Replies: 1
    Last Post: December 13th, 2011, 07:26 AM
  4. Beginner: Show Image in Label when Results Show Up
    By Big Bundy in forum Java Theory & Questions
    Replies: 3
    Last Post: April 4th, 2011, 02:43 PM
  5. Background image on GUI
    By OBLITERATOR in forum AWT / Java Swing
    Replies: 3
    Last Post: March 5th, 2010, 11:10 AM