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...

[124 byte] By [FaiyazAziza] at [2007-11-27 10:11:31]
# 1

javax.swing.popup?

max25a at 2007-7-28 15:14:07 > top of Java-index,Desktop,Core GUI APIs...
# 2

can u please explain me in bit detail.

FaiyazAziza at 2007-7-28 15:14:07 > top of Java-index,Desktop,Core GUI APIs...
# 3

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 :)

gildedwinda at 2007-7-28 15:14:07 > top of Java-index,Desktop,Core GUI APIs...
# 4

> 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!

Ja_Lava_Javaa at 2007-7-28 15:14:07 > top of Java-index,Desktop,Core GUI APIs...