Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.gui > #2990
| From | "Sabine Dinis Blochberger" <sabine.dinis.blochberger@THRWHITE.remove-dii-this> |
|---|---|
| Subject | Re: Trying to put a backg |
| Message-ID | <A62dndYPCPJE-RranZ2dnUVZ8rGdnZ2d@novis.pt> (permalink) |
| Newsgroups | comp.lang.java.gui |
| References | <7e0c42d4def4d@uwe> |
| Date | 2011-04-27 15:42 +0000 |
| Organization | TDS.net |
To: comp.lang.java.gui
Andrew Thompson wrote:
> Sabine Dinis Blochberger wrote:
> >> >Trying to put a background image in a JFrame
> ...
> >In option two, adding one JPanel with BorderLayout.EAST, the other with
> >BorderLayout.SOUTH, all I get is a tiny square off the window bounds.
>
> Images load asynchonously, so maybe the image
> is returning a -1,-1 size at time of pack(). One way
> to fix that is to use a MediaTracker. Knute has some
> good examples of loading and displaying images, here..
> <http://rabbitbrush.frazmtn.com/>
>
>
The new contructor thus looks like this
//---
public BackgroundPanel(String imgName) {
try {
image = createImageIcon(imgName);
// Create a MediaTracker instance,
// to montior loading of images
final MediaTracker tracker = new MediaTracker(this);
// Register it with media tracker
tracker.addImage(image.getImage(), 1);
// Wait until all images have loaded
tracker.waitForAll();
} catch (Exception ex) { ex.printStackTrace(); }
}
//---
It didn't make a difference. The square is a few pixels large, you can
actually see part of the image on it - it's "only" cropped.
Then I tried to change the contentPanes layout, and it actually anchors
the panel as I want:
//---
private void addSimply() {
final JPanel bgPanel = new BackgroundPanel("background.png");
bgPanel.setOpaque(false);
final Container cp = getContentPane();
cp.setLayout(new BorderLayout());
cp.add(bgPanel, BorderLayout.EAST);
bgPanel.setBounds(0, 0, getWidth(), getHeight());
}
//---
However, the BackgroundPanel is now only a few pixels wide, and button 3
is not anchored to the right window edge anymore (I can live without
that though)...
--
Sabine Dinis Blochberger
Op3racional
www.op3racional.eu
---
* Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24
Back to comp.lang.java.gui | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Trying to put a backgroun "Sabine Dinis Blochberger" <sabine.dinis.blochberger@THRWHITE.remove-dii-this> - 2011-04-27 15:42 +0000
Re: Trying to put a backg "Andrew Thompson" <andrew.thompson@THRWHITE.remove-dii-this> - 2011-04-27 15:42 +0000
Re: Trying to put a backg "Sabine Dinis Blochberger" <sabine.dinis.blochberger@THRWHITE.remove-dii-this> - 2011-04-27 15:42 +0000
Re: Trying to put a backg "Sabine Dinis Blochberger" <sabine.dinis.blochberger@THRWHITE.remove-dii-this> - 2011-04-27 15:42 +0000
Re: Trying to put a backg "Andrew Thompson" <andrew.thompson@THRWHITE.remove-dii-this> - 2011-04-27 15:42 +0000
Re: Trying to put a backg "Sabine Dinis Blochberger" <sabine.dinis.blochberger@THRWHITE.remove-dii-this> - 2011-04-27 15:42 +0000
Re: Trying to put a backg "Knute Johnson" <knute.johnson@THRWHITE.remove-dii-this> - 2011-04-27 15:42 +0000
Re: Trying to put a backg "Sabine Dinis Blochberger" <sabine.dinis.blochberger@THRWHITE.remove-dii-this> - 2011-04-27 15:42 +0000
Re: Trying to put a backg "Lew" <lew@THRWHITE.remove-dii-this> - 2011-04-27 15:42 +0000
Re: Trying to put a backg "Sabine Dinis Blochberger" <sabine.dinis.blochberger@THRWHITE.remove-dii-this> - 2011-04-27 15:42 +0000
Re: Trying to put a backg "Andrew Thompson" <andrew.thompson@THRWHITE.remove-dii-this> - 2011-04-27 15:42 +0000
Re: Trying to put a backg "Sabine Dinis Blochberger" <sabine.dinis.blochberger@THRWHITE.remove-dii-this> - 2011-04-27 15:42 +0000
Re: Trying to put a backg "Andrew Thompson" <andrew.thompson@THRWHITE.remove-dii-this> - 2011-04-27 15:42 +0000
csiph-web