• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

background problem

 
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
http://faq.javaranch.com/view?BackgroundImageOnJPanel

Note: the first line of paintComponent() should be
super.paintComponent(g);
 
memati bas
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh,
Thanks very very much for this link...

Best wishes.
 
memati bas
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> 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
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for this...

Best wishes...
 
memati bas
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But, I can not understand the reason for this.

Would you please explain it ??
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Again, thanks very much...
 
Grow a forest with seedballs and this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic