add Image to Jwindow in BorderLayout.CENTER

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Nov 2008
Posts: 20
Reputation: Narayan15 is an unknown quantity at this point 
Solved Threads: 0
Narayan15 Narayan15 is offline Offline
Newbie Poster

add Image to Jwindow in BorderLayout.CENTER

 
0
  #1
Feb 21st, 2009
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
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,489
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 517
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: add Image to Jwindow in BorderLayout.CENTER

 
0
  #2
Feb 21st, 2009
You need to add the scroll pane to your container instead of the text area. Change this
  1. container.add(textArea);
to this
  1. container.add(sp);
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC