tbboyett
asked on
Is it possible to add a web link to a JDialog
Hello, Is it possible to add a web link to a JDialog that will automatically open a web browser and take the user to that page?
you could use a JEditoPane, and add that to your dialog
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi cmaypop,
You can invent something like this:
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.io.*;
import java.net.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
import java.text.*;
public class LinkableDialog extends JDialog implements Runnable, ActionListener {
JLabel jl = new JLabel("www.google.com");
public void init() {
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
System.exit(0);
}
});
jl.setForeground(Color.BLU E);
add(jl);
pack();
center(this);
jl.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
try {
Runtime.getRuntime().exec( "explorer http://"+jl.getText());
} catch(IOException ioe) {
ioe.printStackTrace();
}
}
});
}
public void actionPerformed(ActionEven t ae) {
}
public void run() {
init();
setVisible(true);
}
public void center(Component c) {
Dimension dim = Toolkit.getDefaultToolkit( ).getScree nSize();
setLocation((dim.width - c.getWidth()) / 2, (dim.height - c.getHeight()) / 2);
}
public static void main(String[] args) {
SwingUtilities.invokeLater (new LinkableDialog());
}
}
but this works only on windows with explorer installed
You can invent something like this:
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.io.*;
import java.net.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
import java.text.*;
public class LinkableDialog extends JDialog implements Runnable, ActionListener {
JLabel jl = new JLabel("www.google.com");
public void init() {
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
System.exit(0);
}
});
jl.setForeground(Color.BLU
add(jl);
pack();
center(this);
jl.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
try {
Runtime.getRuntime().exec(
} catch(IOException ioe) {
ioe.printStackTrace();
}
}
});
}
public void actionPerformed(ActionEven
}
public void run() {
init();
setVisible(true);
}
public void center(Component c) {
Dimension dim = Toolkit.getDefaultToolkit(
setLocation((dim.width - c.getWidth()) / 2, (dim.height - c.getHeight()) / 2);
}
public static void main(String[] args) {
SwingUtilities.invokeLater
}
}
but this works only on windows with explorer installed