[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Is it possible to put Panel on the Image

Posted on 2004-04-14
22
Medium Priority
?
221 Views
Last Modified: 2013-11-23
I have a doubt. Can i place a panel on top of the image in the frame?

I have a JFrame where i want the image to be displayed... and i have a JPanel where i want it to be displayed but on top of the image. I am talking about the skin of the GUI...   In VC++, you can do that.. is there a way to do in java??

Thanks in advance
Ram
0
Comment
Question by:rampriya_sb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 5
  • 5
  • +1
22 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 672 total points
ID: 10826205
If you want to float components over the image just override paintComponent, being careful to call super.paintComponent
0
 

Author Comment

by:rampriya_sb
ID: 10826230
can u give me some more clue? some small code snippet wud be appreciated
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10826251
public void paintComponent(Graphics g) {
      super.paintComponent(g);
      // call drawImage here
}

You'll still be able to add components leaving the image there
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 86

Expert Comment

by:CEHJ
ID: 10826257
(oh that's overriding the paintComponent of JPanel btw)
0
 

Author Comment

by:rampriya_sb
ID: 10826391
is it JPanel u r talking about or the JFrame?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10826409
JPanel
0
 
LVL 14

Expert Comment

by:Tommy Braas
ID: 10826551
If you want the image drawn behind the panel, you need to override paintComponent() (see CEHJ's comment) in your JFrame instance.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10826609
You can't do that actually - JFrame has no paintComponent. Easiest to add another JPanel to the frame and then place the final one on that
0
 
LVL 14

Assisted Solution

by:Tommy Braas
Tommy Braas earned 664 total points
ID: 10826727
Oh, my bad.

rampriya_sb, recap of information so far:
Set BorderLayout as your layout manager for the JFrame's content pane
Override paintComponent in a subclass of JPanel, in order to paint the image, as described above
Add an instance of the JPanel described above to the BorderLayout.CENTER of the JFrame
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10826764
>>Set BorderLayout as your layout manager for the JFrame's content pane...

Well of course, it's still not clear what the intention is, so this is probably a little bit too assumptive ;-)
0
 
LVL 14

Expert Comment

by:Tommy Braas
ID: 10826837
>> probably a little bit too assumptive
possibly, but not if he wants the image to cover the complete area of the JFrame
0
 

Author Comment

by:rampriya_sb
ID: 10826847
I want the image to cover the entire area and place a Panel on the image...
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10826874
Should be OK then
0
 
LVL 14

Expert Comment

by:Tommy Braas
ID: 10826970
yep, I think that's it! ;-)
0
 

Author Comment

by:rampriya_sb
ID: 10827156
As suggested, i overrode paintComponent method and put the image

class TestPanel extends JPanel
{

JPanel pnlAnotherPanel;
public TestPanel()
{
    pnlAnotherPanel = new JPanel();
    pnlAnotherPanel.setBackground(Color.white);
    pnlAnotherPanel.setBounds(new Rectangle(30,30,60,80));
    this.add(pnlAnotherPanel,null);
}

public void paintComponent(Graphics g)
{
  super.paintComponent(g);
  Image img=Toolkit.getDefaultToolkit().getImage("testimg.jpg");
  g.drawImage(img,0,0,this);
}
}

When i try to put this JPanel class to the Frame and try to runthe program, only the image is displayed and not the panel(pnlAnotherPanel)..... so what shud i do for that? i tried setting the panel to opaque, but didnt help...
 

Then i tried putting
0
 

Author Comment

by:rampriya_sb
ID: 10827774
i m not finding any luck still.... shud i put the panel in the paintComponent method??
0
 
LVL 92

Assisted Solution

by:objects
objects earned 664 total points
ID: 10827842
Theres no need to override paintComponent, just add your panel to whatever component is displaying your image.

eg.

JLabel back = new JLabel(image);
JPanel panel = new JPanel();
back.add(panel);
0
 
LVL 92

Expert Comment

by:objects
ID: 10827879
If you instead want the panel to float above your existing component hierarchy then add the panel to the glass pane or a layered pane.
http://java.sun.com/docs/books/tutorial/uiswing/components/rootpane.html
0
 
LVL 14

Expert Comment

by:Tommy Braas
ID: 11046310
Three way point split
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question