my dog learned polymorphism*
The moose likes Swing / AWT / SWT and the fly likes background problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "background problem" Watch "background problem" New topic
Author

background problem

memati bas
Ranch Hand

Joined: Jan 29, 2006
Posts: 85
Hi everyone,
I want to put an image to the background of my tab(panel) in the TabbedPane, but I do not know how to do it.
So how can I do this ?
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
http://faq.javaranch.com/view?BackgroundImageOnJPanel

Note: the first line of paintComponent() should be
super.paintComponent(g);
memati bas
Ranch Hand

Joined: Jan 29, 2006
Posts: 85
Oh,
Thanks very very much for this link...

Best wishes.
memati bas
Ranch Hand

Joined: Jan 29, 2006
Posts: 85
Hi,
At the below codes, I set a background image to the panel and then I add this panel to a JDialog but when I execute this, the image does not cover all the dialog screen. Why ??


Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> the image does not cover all the dialog screen. Why ??

due to this line
dialog.setLayout(new FlowLayout() );

comment out the line, run the program, see the difference

for reasons, read up on LayoutManagers
http://java.sun.com/docs/books/tutorial/uiswing/layout/visual.html
memati bas
Ranch Hand

Joined: Jan 29, 2006
Posts: 85
Thanks for this...

Best wishes...
memati bas
Ranch Hand

Joined: Jan 29, 2006
Posts: 85
But, I can not understand the reason for this.

Would you please explain it ??
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
the default layout for JDialog is BorderLayout

when adding only one component to the dialog, and not specifying a location,
it defaults to BorderLayout.CENTER, meaning it (new MultiPanel()) will occupy
all of the available space (600,600)

changing the layout to flowlayout means components will be added to it
at their preferred size. In this case, probably the 'normal' size of the image.
To check, add a border to the MutiPanel.
memati bas
Ranch Hand

Joined: Jan 29, 2006
Posts: 85
Again, thanks very much...
 
Consider Paul's rocket mass heater.
 
subject: background problem