how to generate a popup window?
i want to click on a link...in response of this a popup window opens and show the details...help me regarding this...
i want to click on a link...in response of this a popup window opens and show the details...help me regarding this...
javax.swing.popup?
can u please explain me in bit detail.
details of javax.swing.Popup :
http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/Popup.html
Give the methods a good look over and it should become clear what you need to do. If not, give the tutorials here a good go over:
http://java.sun.com/docs/books/tutorial/uiswing/events/eventsandcomponents.html
Everything you need is right there :)
> can u please explain me in bit detail.
I can try...
About Popup
A Popup is displaying a Component somewhere on (or outside) the screen. When you create a new Popup object you specify the coordinates of the Popup relative to another Component (this other Component could be null)
How to use it
You should create your own subclass of javax.swing.Popup to use a Popup, because the constructors are Protected. I have an example for you. Also have a look at the API or some of the links other people have listed.
Example
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.event.*;
public class PopupEx extends JFrame{
private javax.swing.Popup pop;
private JLabel lab = new JLabel("text");
public static void main(String args[]){
PopupEx f = new PopupEx();
}
public PopupEx(){
//setting the JLabel and placing it in the JFrame
lab.setBackground(Color.red);
lab.setOpaque(true);
lab.setFont(new Font("Curier",Font.PLAIN,200));
add(lab);
pack(); //setting the size of the JFrame
//popup
pop = new Poppy(this, new JPanel(), 10, this.getWidth()/2) ;
pop.show(); //makes the Poppy show at the position (10, this.getWidth()/2) - relative to this
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
}
public class Poppy extends Popup implements ActionListener{
private JPanel pan;
private JLabel mess = new JLabel("I love Java!");
private JButton b= new JButton("ok");
//Constructor
//Overrides the Popup(Component owner,Component contents,int x,int y)
public Poppy(Component owner, JPanel contents, int x, int y){
super(owner,contents,x,y);
pan = contents;
pan.setBackground(Color.yellow);
mess.setFont(new Font("Curier",Font.PLAIN,20));
pan.add(mess);
pan.add(b);
b.addActionListener(this);
}
public void actionPerformed(ActionEvent e){
this.hide();
}
}//end of Poppy
}
If you have questions, just ask!