Hi,
How to add image to Jwindow. Here is my code:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.text.*;
import java.io.*;
class Project4 extends JWindow
{

    Container container;
    JTextField jt;
    JButton jb;
    public Project4(String st, final Image image)
    {

        container = getContentPane();
        container.setLayout(new BorderLayout());
        //JTextArea jtp = new JTextArea(st,10,10);

        //container.add(sp);
        container.add(new JButton("RGUKT Examinations"),BorderLayout.NORTH);
        container.add(new JButton("Close"),BorderLayout.SOUTH);
        container.add(new JButton(""),BorderLayout.EAST);
        container.add(new JButton(""),BorderLayout.WEST);
        JTextArea textArea = new JTextArea()
        {

            {setOpaque(false);}

            public void paintComponent (Graphics g)
            {
                g.drawImage(image, 0, 0, (int)getSize().getWidth(), (int)getSize().getHeight(), this);
                //g.drawImage(grayImage, 0, 0, (int)getSize().getWidth(), (int)getSize().getHeight(), this);
                super.paintComponent(g);
            }
        };
        JScrollPane sp=new JScrollPane(textArea);
        sp.createVerticalScrollBar();
        container.add(textArea);

    }
    public static void main(String[] args) throws IOException
    {
        FileInputStream fl1= new FileInputStream("Project2.java");
        DataInputStream in = new DataInputStream(fl1);
        BufferedReader br = new BufferedReader(new InputStreamReader(in));
        String strLine, st="";
        while ((strLine = br.readLine()) != null)   
        {
        st+=strLine;
        st+="\n";
        }   
        Toolkit toolkit = Toolkit.getDefaultToolkit();
        Image image = toolkit.createImage("bg.jpg");
        Project4 demo = new Project4(st,image);
        //demo.setDefaultCloseOperation(JWindow.EXIT_ON_CLOSE);
        demo.setSize(1200,800);
        demo.setVisible(true);
        demo.setAlwaysOnTop(true);


    }

}

I got Image in center in border Layout. but i didn't get Scrollbar.
Please please help me.
Thanks in advance

You need to add the scroll pane to your container instead of the text area. Change this

container.add(textArea);

to this

container.add(sp);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.