• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

background problem

 
memati bas
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 ?
 
Michael Dunn
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...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic