当前位置: 技术问答>java相关
怎样改变一个对话框的尺寸,位置
来源: 互联网 发布时间:2014-12-28
本文导语: 大侠,你好: 请问怎样在显示对话框之前,设定这个对话框的尺寸,位置? setSize()似乎没用 Thanks Dennistan | //希望能对你有用. import java.awt.*; import java.awt.event.*; import javax.swing.*; public class AboutDial...
大侠,你好:
请问怎样在显示对话框之前,设定这个对话框的尺寸,位置?
setSize()似乎没用
Thanks
Dennistan
请问怎样在显示对话框之前,设定这个对话框的尺寸,位置?
setSize()似乎没用
Thanks
Dennistan
|
//希望能对你有用.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class AboutDialog extends JFrame{
JButton button = new JButton("About");
public AboutDialog(){
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {System.exit(0);}
});
Container contentPane = getContentPane();
contentPane.add(button,BorderLayout.CENTER);
pack();
setSize(300,300);//jframe
setLocation(200,200);//jframe
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent se) {
try { new About().show();
}
catch (Exception mue) {
System.out.println("Error");
}
}
});
}
public static void main(String args[]){
new AboutDialog().show();
}
}
class About extends JDialog{
public About(){
setLocation(240,150);//jdialog
setVisible(true); //jdialog
setSize(100,100);//jdialog
}
}
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class AboutDialog extends JFrame{
JButton button = new JButton("About");
public AboutDialog(){
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {System.exit(0);}
});
Container contentPane = getContentPane();
contentPane.add(button,BorderLayout.CENTER);
pack();
setSize(300,300);//jframe
setLocation(200,200);//jframe
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent se) {
try { new About().show();
}
catch (Exception mue) {
System.out.println("Error");
}
}
});
}
public static void main(String args[]){
new AboutDialog().show();
}
}
class About extends JDialog{
public About(){
setLocation(240,150);//jdialog
setVisible(true); //jdialog
setSize(100,100);//jdialog
}
}