3

这是我在 Stackoverflow 中的第一个问题。我从这里收集了很多页面,并没有解决我的问题。我的问题有时(并非总是)我创建的 jframe 与我在属性中设置的大小不同。我使用 Netbeans 7.1.2 并且只拖放用于 GUI 制作。我还不能进行 GUI 编码。这是例如图片

我的窗口组件看起来像被裁剪了。运行时的大小和属性中的大小(最小和首选大小)不同。这发生在自由设计或绝对设计中。这是什么问题?你知道这通常有什么问题吗?我不知道会发生什么。我该如何解决这个问题?我对错误感到抱歉。谢谢你。

我不知道代码中的错误在哪里,但这是该框架的代码:

@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {

    jButton4 = new javax.swing.JButton();
    jSeparator1 = new javax.swing.JSeparator();
    btBack = new javax.swing.JButton();
    jButton5 = new javax.swing.JButton();
    jLabel1 = new javax.swing.JLabel();
    btNext = new javax.swing.JButton();
    jLabel10 = new javax.swing.JLabel();
    jLabel2 = new javax.swing.JLabel();
    jSeparator2 = new javax.swing.JSeparator();
    jLabel3 = new javax.swing.JLabel();
    jLabel4 = new javax.swing.JLabel();
    jLabel5 = new javax.swing.JLabel();
    jLabel6 = new javax.swing.JLabel();
    jLabel7 = new javax.swing.JLabel();
    lbJudul = new javax.swing.JLabel();
    jPanel1 = new javax.swing.JPanel();

    jButton4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/otodidak/gambar/logomati.png"))); // NOI18N
    jButton4.setToolTipText("Tutup Otodidak");
    jButton4.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jButton4ActionPerformed(evt);
        }
    });

    setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
    setTitle("Otodidak");
    setAlwaysOnTop(true);
    setLocationByPlatform(true);
    setPreferredSize(new java.awt.Dimension(787, 410));
    setResizable(false);
    getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
    getContentPane().add(jSeparator1, new org.netbeans.lib.awtextra.AbsoluteConstraints(48, 53, 689, -1));

    btBack.setIcon(new javax.swing.ImageIcon(getClass().getResource("/otodidak/gambar/backlogo2.png"))); // NOI18N
    btBack.setToolTipText("Kembali");
    btBack.addMouseListener(new java.awt.event.MouseAdapter() {
        public void mouseClicked(java.awt.event.MouseEvent evt) {
            btBackMouseClicked(evt);
        }
    });
    btBack.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            btBackActionPerformed(evt);
        }
    });
    getContentPane().add(btBack, new org.netbeans.lib.awtextra.AbsoluteConstraints(224, 340, 130, -1));

    jButton5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/otodidak/gambar/logomati.png"))); // NOI18N
    jButton5.setToolTipText("Tutup Otodidak");
    jButton5.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jButton5ActionPerformed(evt);
        }
    });
    getContentPane().add(jButton5, new org.netbeans.lib.awtextra.AbsoluteConstraints(718, 358, 46, -1));

    jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/otodidak/gambar/synapticwvdial.png"))); // NOI18N
    getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(388, 65, 348, 264));

    btNext.setIcon(new javax.swing.ImageIcon(getClass().getResource("/otodidak/gambar/nextlogo2.png"))); // NOI18N
    btNext.setToolTipText("Lanjut");
    btNext.addMouseListener(new java.awt.event.MouseAdapter() {
        public void mouseClicked(java.awt.event.MouseEvent evt) {
            btNextMouseClicked(evt);
        }
    });
    getContentPane().add(btNext, new org.netbeans.lib.awtextra.AbsoluteConstraints(396, 340, 130, 48));

    jLabel10.setFont(new java.awt.Font("Ubuntu", 1, 48)); // NOI18N
    jLabel10.setText("1");
    getContentPane().add(jLabel10, new org.netbeans.lib.awtextra.AbsoluteConstraints(48, 68, 36, 40));

    jLabel2.setFont(new java.awt.Font("Ubuntu", 0, 24)); // NOI18N
    jLabel2.setText("Instal Aplikasi wvdial");
    getContentPane().add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(90, 80, -1, 24));
    getContentPane().add(jSeparator2, new org.netbeans.lib.awtextra.AbsoluteConstraints(50, 116, 216, 18));

    jLabel3.setFont(new java.awt.Font("Ubuntu", 0, 16)); // NOI18N
    jLabel3.setText("1) Buka Synaptic.");
    getContentPane().add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(56, 132, 368, 26));

    jLabel4.setFont(new java.awt.Font("Ubuntu", 0, 16)); // NOI18N
    jLabel4.setText("3) Klik kanan wvdial, pilih mark for Installation. ");
    getContentPane().add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(56, 207, 346, -1));

    jLabel5.setFont(new java.awt.Font("Ubuntu", 0, 16)); // NOI18N
    jLabel5.setText("2) Ketik wvdial. ");
    getContentPane().add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(56, 170, 346, -1));

    jLabel6.setFont(new java.awt.Font("Ubuntu", 0, 16)); // NOI18N
    jLabel6.setText("4) Biarkan Synaptic menginstalkan wvdial. ");
    getContentPane().add(jLabel6, new org.netbeans.lib.awtextra.AbsoluteConstraints(56, 244, 346, -1));

    jLabel7.setFont(new java.awt.Font("Ubuntu", 0, 16)); // NOI18N
    jLabel7.setText("Catatan: internet harus menyala.");
    getContentPane().add(jLabel7, new org.netbeans.lib.awtextra.AbsoluteConstraints(58, 292, 298, 22));

    lbJudul.setFont(new java.awt.Font("Dialog", 1, 24)); // NOI18N
    lbJudul.setForeground(new java.awt.Color(254, 254, 254));
    lbJudul.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    lbJudul.setText("Cara Menginstal Smartfren AC682");
    getContentPane().add(lbJudul, new org.netbeans.lib.awtextra.AbsoluteConstraints(117, 12, 578, -1));

    jPanel1.setBackground(new java.awt.Color(1, 1, 1));
    getContentPane().add(jPanel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, -2, 788, 50));

    pack();

不是完整的代码,但可能有用。谢谢大家的关注...

4

1 回答 1

5
...AbsoluteConstraints(117, 12, 578, -1)  

这是问题的基础。null使用时它与布局一样有效pack()

解决方案很简单。使用符合组件首选尺寸的布局管理器。

于 2013-01-28T14:28:22.563 回答