怎么把一个对话筐指定在显示的位置显示 如 我按下个Button,我希望在个对话筐在下放显示 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 import java.awt.BorderLayout;import java.awt.Point;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JButton;import javax.swing.JDialog;import javax.swing.JFrame;import javax.swing.SwingUtilities;public class T { public static void main(String[] args) { JButton btn = new JButton("Test"); btn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JButton button = (JButton) e.getSource(); JDialog dialog = new JDialog( (JFrame) SwingUtilities.getAncestorOfClass(JFrame.class, button), "Test", true); dialog.setSize(200, 200); Point p = button.getLocationOnScreen(); dialog.setLocation(p.x, p.y + button.getHeight()); dialog.show(); } }); JFrame f = new JFrame(); f.getContentPane().add(btn, BorderLayout.CENTER); f.pack(); f.setLocationRelativeTo(null); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); }} Java Socket 连接超时问题 JTree展开后又折叠 DefaultListModel的问题 一个简单的关于字符串的题,谁能告诉我怎么做? 关于String与StringBuffer作为参数的不同? 【j2nix】Java 中文问题彻底分析和解决 关于以下inputStream的两种使用方法有何区别 请问一个关于Applet的问题(急)? 请问Java怎样能读取共享文件夹里的东西。 在线求助! 请教 笔试时遇到的问题! 在jdk1.3中有什么办法替换jdk1.4的replaceAll的方法?
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;public class T {
public static void main(String[] args) {
JButton btn = new JButton("Test");
btn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JButton button = (JButton) e.getSource();
JDialog dialog = new JDialog(
(JFrame) SwingUtilities.getAncestorOfClass(JFrame.class, button),
"Test", true);
dialog.setSize(200, 200);
Point p = button.getLocationOnScreen();
dialog.setLocation(p.x, p.y + button.getHeight());
dialog.show();
}
});
JFrame f = new JFrame();
f.getContentPane().add(btn, BorderLayout.CENTER);
f.pack();
f.setLocationRelativeTo(null);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
}