j**a窗体居中显示

时间:2013.09.03 发布人:comer88

j**a窗体居中显示

已解决问题

谷歌comer88用户在2013.09.03提交了关于“捡个校花做老婆j**a窗体居中显示”的提问,欢迎大家涌跃发表自己的观点。目前共有1个回答,最后更新于2024-07-30T09:06:16。packagedemo;

importj**a.awt.BorderLayout;
importj**a.awt.Container;
importj**a.io.File;
importj**ax.swing.Icon;
importj**ax.swing.ImageIcon;
importj**ax.swing.JDesktopPane;
importj**ax.swing.JFrame;
importj**ax.swing.JInternalFrame;
importj**ax.swing.JLabel;
importj**ax.swing.JPanel;
importj**ax.swing.JScrollPane;
publicclassDemo3{
publicstaticvoidmain(Stringargs[]){
JFramef=newJFrame("美女");
Containercont=f.getContentPane();
JDesktopPanedesk=newJDesktopPane();
cont.add(desk,***.CENTER);
cont.add(newJLabel("**窗体"),BorderLayout.SOUTh**);
Stringpicpath="g:"+File.separator+"2.jpg";
Iconicon=newImageIcon(picpath);
JInternalFrameter=newJInternalFrame("美女",false,false,false,true);
JPanelpan2=newJPanel();
JLabellab=newJLabel(icon);
pan2.add(lab);
JScrollPanescr=**ll;
scr=newJScrollPane(pan2,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.h**ORIZONTAL_SCROLLBAR_ALWAYS);
ter.add(scr);
ter.setSize(480,500);
ter.setVisible(true);
desk.add(ter);
f.setSize(500,600);
f.setVisible(true);
}
}
帮忙修改一下代码,让窗体居中显示!希望大家能够帮助她。

详细问题描述及疑问:packagedemo;

importj**a.awt.BorderLayout;
importj**a.awt.Container;
importj**a.io.File;
importj**ax.swing.Icon;
importj**ax.swing.ImageIcon;
importj**ax.swing.JDesktopPane;
importj**ax.swing.JFrame;
importj**ax.swing.JInternalFrame;
importj**ax.swing.JLabel;
importj**ax.swing.JPanel;
importj**ax.swing.JScrollPane;
publicclassDemo3{
publicstaticvoidmain(Stringargs[]){
JFramef=newJFrame("美女");
Containercont=f.getContentPane();
JDesktopPanedesk=newJDesktopPane();
cont.add(desk,***.CENTER);
cont.add(newJLabel("**窗体"),BorderLayout.SOUTh**);
Stringpicpath="g:"+File.separator+"2.jpg";
Iconicon=newImageIcon(picpath);
JInternalFrameter=newJInternalFrame("美女",false,false,false,true);
JPanelpan2=newJPanel();
JLabellab=newJLabel(icon);
pan2.add(lab);
JScrollPanescr=**ll;
scr=newJScrollPane(pan2,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.h**ORIZONTAL_SCROLLBAR_ALWAYS);
ter.add(scr);
ter.setSize(480,500);
ter.setVisible(true);
desk.add(ter);
f.setSize(500,600);
f.setVisible(true);
}
}
帮忙修改一下代码,让窗体居中显示!期待您的答案,当代劳模,所有人都应该向你学习 !

希望以下的回答,能够帮助你。

第1个回答

用户名:qcup1291  

mypl8110627的方法当然是可以的,但是如果要考虑任差紧点额而里术液务栏高度之类的还要短调用getScreenInsets()方法。
其实有一个更简单的方法,只要一句话:你在f.setSi王ze(500,6来自00);下面再加上:f.setLocationRelativeTo(**ll);就OK了。