我在Eclipse 新建立了一个可视类,继承自JFrame,但不能出现可视化界面:即:那个JFrame 窗体不会出现在设计试图中,请问怎么回事,谢谢:)

解决方案 »

  1.   

    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JButton;
    import javax.swing.JCheckBox;
    import javax.swing.JTextField;
    import java.awt.BorderLayout;
    import javax.swing.JDialog;
    import javax.swing.JTextArea;
    import javax.swing.JTable;
    import javax.swing.JWindow;
    import javax.swing.JComboBox;
    import javax.swing.JOptionPane;
    /*
     * Created on 2005/06/15
     *
     * TODO To change the template for this generated file go to
     * Window - Preferences - Java - Code Style - Code Templates
     *//**
     * @author Administrator
     *
     * TODO To change the template for this generated type comment go to
     * Window - Preferences - Java - Code Style - Code Templates
     */
    public class test extends JFrame { private JPanel jPanel = null;
    private JLabel jLabel = null;
    private JButton jButton = null;
    private JCheckBox jCheckBox = null;
    private JTextField jTextField = null;
    private JPanel jContentPane = null;
    private JDialog jDialog = null;  //  @jve:decl-index=0:visual-constraint="538,26"
    private JTextArea jTextArea = null;
    private JButton jButton1 = null;
    private JLabel jLabel1 = null;
    private JTable jTable = null;
    private JPanel jContentPane1 = null;
    private JWindow jWindow = null;  //  @jve:decl-index=0:visual-constraint="575,180"
    private JTextField jTextField1 = null;
    private JComboBox jComboBox = null;
    private JButton jButton2 = null;
    private JOptionPane jOptionPane = null;
    private JButton jButton3 = null;
    /**
     * This method initializes 
     * 
     */
    public test() {
    super();
    initialize();
    }
    /**
     * This method initializes this
     * 
     * @return void
     */
    private void initialize() {
            this.setContentPane(getJPanel());
            this.setSize(529, 237);

    }
    /**
     * This method initializes jPanel
     * 
     * @return javax.swing.JPanel
     */    
    private JPanel getJPanel() {
    if (jPanel == null) {
    jLabel1 = new JLabel();
    jLabel = new JLabel();
    jPanel = new JPanel();
    jPanel.setLayout(null);
    jLabel.setBounds(26, 19, 103, 33);
    jLabel.setText("JLabel");
    jLabel1.setBounds(27, 69, 96, 34);
    jLabel1.setText("JLabel");
    jPanel.add(jLabel, null);
    jPanel.add(getJButton(), null);
    jPanel.add(getJCheckBox(), null);
    jPanel.add(getJTextField(), null);
    jPanel.add(jLabel1, null);
    jPanel.add(getJTable(), null);
    jPanel.add(getJContentPane1(), null);
    jPanel.add(getJButton2(), null);
    jPanel.add(getJButton3(), null);
    jPanel.add(getJOptionPane(), null);
    }
    return jPanel;
    }
    /**
     * This method initializes jButton
     * 
     * @return javax.swing.JButton
     */    
    private JButton getJButton() {
    if (jButton == null) {
    jButton = new JButton();
    jButton.setBounds(126, 155, 136, 33);
    jButton.setText("Open a Dialog");
    jButton.addMouseListener(new java.awt.event.MouseAdapter() { 
    public void mouseClicked(java.awt.event.MouseEvent e) {    
    System.out.println("mouseClicked()"); // TODO Auto-generated Event stub mouseClicked()
                        jDialog.setSize(500,500);
                        jDialog.show();
                       
                    }
    });
    }
    return jButton;
    }
    /**
     * This method initializes jCheckBox
     * 
     * @return javax.swing.JCheckBox
     */    
    private JCheckBox getJCheckBox() {
    if (jCheckBox == null) {
    jCheckBox = new JCheckBox();
    jCheckBox.setBounds(151, 66, 79, 26);
    }
    return jCheckBox;
    }
    /**
     * This method initializes jTextField
     * 
     * @return javax.swing.JTextField
     */    
    private JTextField getJTextField() {
    if (jTextField == null) {
    jTextField = new JTextField();
    jTextField.setBounds(146, 19, 92, 33);
    }
    return jTextField;
    }
    /**
     * This method initializes jContentPane
     * 
     * @return javax.swing.JPanel
     */    
    private JPanel getJContentPane() {
    if (jContentPane == null) {
    jContentPane = new JPanel();
    jContentPane.setLayout(new BorderLayout());
    jContentPane.add(getJTextArea(), java.awt.BorderLayout.WEST);
    jContentPane.add(getJButton1(), java.awt.BorderLayout.CENTER);
    }
    return jContentPane;
    }
    /**
     * This method initializes jDialog
     * 
     * @return javax.swing.JDialog
     */    
    private JDialog getJDialog() {
    if (jDialog == null) {
    jDialog = new JDialog(this);
    jDialog.setContentPane(getJContentPane());
    jDialog.setSize(112, 137);
    }
    return jDialog;
    }
    /**
     * This method initializes jTextArea
     * 
     * @return javax.swing.JTextArea
     */    
    private JTextArea getJTextArea() {
    if (jTextArea == null) {
    jTextArea = new JTextArea();
    }
    return jTextArea;
    }
    /**
     * This method initializes jButton1
     * 
     * @return javax.swing.JButton
     */    
      

  2.   

    如果没有 可视化编辑器插件当然不会出现设计视图。对文件 test.java 点击右键,看看 弹出菜单中 >> Open With 中有没有可视化的 编辑器 ?