}
Java codeimport java.awt.Container;
import java.awt.Frame;
import java.awt.GraphicsEnvironment;
import javax.swing.*;
import javax.swing.event.*;
public class FontDialog extends JDialog {
private JLabel fontLabel = new JLabel("字体(F)");
private JTextField fontTextField = new JTextField();
private Container contentPane = getContentPane();
private JScrollPane fontScrollPane = new JScrollPane();
private GraphicsEnvironment graEnviro = GraphicsEnvironment
.getLocalGraphicsEnvironment();
private String[] fontNames = graEnviro.getAvailableFontFamilyNames();
private JList fontList = new JList(fontNames);
public FontDialog(JFrame f,boolean m) {
super(f,m);
this.setSize(400, 500);
this.setVisible(true);
this.setLayout(null);
// this.setDefaultCloseOperation(EXIT_ON_CLOSE);
init();
}
private void init() {
fontLabel.setSize(160, 25);
fontLabel.setLocation(10, 10);
contentPane.add(fontLabel);
fontTextField.setSize(160, 25);
fontTextField.setLocation(10, 35);
contentPane.add(fontTextField);
fontScrollPane.setSize(160, 120);
fontScrollPane.setLocation(10, 60);
contentPane.add(fontScrollPane);
fontScrollPane.setViewportView(fontList);
fontScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER );
fontList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
fontList.addListSelectionListener(new ListSelectionListener(){
public void valueChanged(ListSelectionEvent event){
String s = (String)fontList.getSelectedValue();
fontTextField.setText(s);
}
});
}
public static void main(String[] args) {
try{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}catch(Exception e){
e.printStackTrace();
}
}}
只能把这个界面缩小到任务栏,然后再激活,才会显示所有组件。
对于所有运行的GUI程序都是这种情况,比如我运行一个JDialog,也是这样,不显示任何内容,虽然dialog不能缩小至任务栏再激活,但是点dialog的关闭按钮,它不会关闭,而是显示没有显示的组件,变正常。
在别人的电脑上都能一次性正常显示,就是我的不行。我卸载了jre又重新安装,还是那样。我不使用eclipse而用命令行编译过后,在执行,依旧是那样。抓狂了