Results 1 to 4 of 4
  1. #1
    mmcnitt is offline Member
    Join Date
    Mar 2011
    Posts
    3
    Rep Power
    0

    Default Adding multiple components to 1 container index

    Ok so i'm new to GUI's in java basically what i'm trying to accomplish:

    I'm drawing a screen that has objects oriented to a grid, displaying numbers in JLabels and Graphics over the numbers.

    for example, the issue i'm having currently is i have a container and i'm using setLayout(new GridLayout)

    which gives me a grid. in 1 of the grids i have a JLabel displaying a number 85% and behind that number i want to draw a rectangle only 85% full. I have the JLabel displaying the number and I have the rectangle, but i do not know how to put them in the same square on the grid. I tried looking into LayeredPanes but i think i just didn't understand it, Does anyone have an idea on what would be the easiest way to do this? I'm not asking for someone to do the work, just simply what would be the best way to put 2 objects in the same grid square?

    I add them by using contentPane.add(JLabel) i also tried giving both objects the same index but that didn't work. any help is greatly appreciated

    this is what i'm trying to make it look like, black is background orange is the drawing and 100% is the JLabel
    Last edited by mmcnitt; 03-06-2011 at 04:24 PM. Reason: add pic

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default

    Just setBackground(...) of the JLabel and setOpaque(true)

    db

  3. #3
    mmcnitt is offline Member
    Join Date
    Mar 2011
    Posts
    3
    Rep Power
    0

    Default

    set.Background just sets a color, i need to actually draw a rectangle behind it, the reasoning being that i only want the rectangle to be as full as the JLabels percentage

  4. #4
    mmcnitt is offline Member
    Join Date
    Mar 2011
    Posts
    3
    Rep Power
    0

    Default

    ok so what i ended up doing is instead of using a JLabel i'm using drawString, that way instead of having 2 objects it's draw with the rectangle, thanks all for looking though, and if theres a better way please let me know

Similar Threads

  1. Help with adding a Container within a Container
    By JoKeR313 in forum New To Java
    Replies: 4
    Last Post: 01-02-2011, 04:59 AM
  2. Adding and removing components from a GridBagLayout
    By peterhabe in forum New To Java
    Replies: 4
    Last Post: 09-19-2010, 10:13 PM
  3. Trying to Draw Multiple Components
    By habester in forum New To Java
    Replies: 1
    Last Post: 11-09-2009, 11:06 PM
  4. Adding components to a panel
    By jboy in forum New To Java
    Replies: 1
    Last Post: 10-10-2009, 01:02 PM
  5. adding components to frame
    By roaan in forum New To Java
    Replies: 4
    Last Post: 07-05-2009, 03:30 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
  •