Results 1 to 3 of 3
  1. #1
    TOAA is offline Member
    Join Date
    Jun 2015
    Posts
    8
    Rep Power
    0

    Default How to set the window background image, include multiple buttons, and add text

    Hello great community, thanks for taking the time to look at this post i hope i dont offend any developers of my amateurness but im in deep trouble, im trying to set an image for my app and have some buttons that run things like opening a url, etc. simple stuff, then adding some text to it to describe the buttons, however, as im learning how to add buttons, then add images, i cannot blend them or combine them together, it seems that every time i find a solution for a piece of my app, it's incompatible with another, but enough of my rambles, let me show you the code im running:

    package x(name of my package);

    import javax.swing.*;
    import java.awt.*;

    class x(name of my class) extends JFrame

    {

    private static final long serialVersionUID = 1L;

    JButton b1;
    JLabel l1;

    public button()
    {
    setTitle("Background Color for JFrame");
    setSize(1440,1080);
    setLocationRelativeTo(null);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setVisible(true);

    setLayout(new BorderLayout());
    setContentPane(new JLabel(new ImageIcon("C:\\Users\\x(name of computer)\\Downloads\\helena.jpg")
    setLayout(new FlowLayout());
    l1=new JLabel("here is a button");
    b1=new JButton("I am a button");
    add(l1);
    add(b1);
    setSize(1,1);
    setSize(1440,,1080);

    }

    public static void main(String[] args){

    new button();
    }

    }

    /* Running this yields background image along with my buttons, however when trying to implement this code for some text on the background image, i get a bunch of errors and so my question is... with this code, how do i implement text ontop of the background image? How do i make my buttons run things? how do i customize my buttons with images?

    **code:
    Graphics g = image.getGraphics();
    g.setFont(g.getFont().deriveFont(30f));
    g.drawString("Hello World!", 100, 100);
    g.dispose();

    i appreciate all the help and thanks!
    */

  2. #2
    Artemia is offline Member
    Join Date
    May 2015
    Location
    Netherlands
    Posts
    39
    Rep Power
    0

    Default Re: How to set the window background image, include multiple buttons, and add text

    I'm not sure I understand exactly what you want, but I had some trouble with adding a background pick to a small application a while back, it was an application to calculate the quality of a video.
    in the end I got what I wanted and it turned out like this:

    How to set the window background image, include multiple buttons, and add text-vqc.jpg

    the image itself is on the main frame, all the components are made transparent. (I chose not to make the calculate button transparent)

    if that's about what you want, you need to look into the 'setOpaque' settings of the components.
    if you can't find a tutorial about it on the forum somewhere you can find out about it through google :)
    Last edited by Artemia; 06-11-2015 at 08:36 AM.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    26

    Default Re: How to set the window background image, include multiple buttons, and add text

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. How to include a line number in a Text Area
    By chyrl in forum AWT / Swing
    Replies: 1
    Last Post: 11-06-2010, 05:44 PM
  2. Replies: 13
    Last Post: 09-29-2010, 10:55 PM
  3. Background color of window
    By Annie George in forum NetBeans
    Replies: 1
    Last Post: 09-18-2010, 09:52 AM
  4. Replies: 0
    Last Post: 02-11-2009, 11:12 PM
  5. window background color?
    By javan00b in forum New To Java
    Replies: 3
    Last Post: 01-29-2008, 10:43 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
  •