We help IT Professionals succeed at work.

can a JPEG image can be added to JInternalFrame

globalkiran
globalkiran asked
on
Hello, can i add a jpeg image as background to JInternalFrame.
Even though i added this,its getting added to JFrame.
Please help in this regard
Comment
Watch Question

Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
Can you please grade this question or comment why the solution is not suitable:

http://itworld.experts-exchange.com/jsp/qShow.jsp?ta=java&qid=20154718
Commented:
Here's how you add an image to a JInternalFrame:

public class MyInternalFrame extends JInternalFrame {

    public MyInternalFrame(String title) {
        super(title, true, true, true, true);
        ImageIcon imageIcon = new ImageIcon(getClass().getResource("background.jpg"));
        JLabel imageLabel = new JLabel(imageIcon);
        JPanel panel = new JPanel(new BorderLayout());
        panel.add(imageLabel, Borderlayout.CENTER);
        getContentPane().add(panel);
        setSize(new Dimension(400, 400));
        setLocation(0, 0);
        show();
    }
}

Here's how you instantiate a MyInternalFrame object and add to the desktop pane:

MyInternalFrame internalFrame = new MyInternalFrame("Demo");
desktopPane.add(internalFrame); // desktopPane is your JDesktopPane

Commented:
BTW, you have asked 5 questions and graded 0. There is one question which is solved by Jim Cakalic. You thanked him, but you never graded the question.

Author

Commented:
Hi yongsing,

i know this but what i want is

the Jpg(image) should be as the background of the Internal frame and i have to add all components(like buttons,labels) as usual to that InternalFrame,and For JFrame its working,

KiranKumar

Author

Commented:
Hi yongsing,

i know this but what i want is

the Jpg(image) should be as the background of the Internal frame and i have to add all components(like buttons,labels) as usual to that InternalFrame,and For JFrame its working,

KiranKumar

Commented:
You can use JLayeredPane to do it.

Commented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

- Points for yongsing

Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
Venabili
EE Cleanup Volunteer

Explore More ContentExplore courses, solutions, and other research materials related to this topic.