JTable:将一个添加到一个JPanel,它不会显示自己 [英] JTable: Adding one to a JPanel, and it not displaying itself

查看:90
本文介绍了JTable:将一个添加到一个JPanel,它不会显示自己的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是星期一的早晨,这意味着我该在Java Swing上失败了!但是,说真的,我无法弄清楚为什么动态创建的JTable一旦添加到JFrame的JPanel后就拒绝显示自己,并且非常感谢您为解决这个麻烦的问题提供了帮助.从代码中可以看到,我已经调用了十二种不同的方法,但是似乎找不到合适的方法来显示它……也许我错过了吗?

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package energizingemerald;


import javax.swing.*;
import java.awt.Dimension;
/**
 *
 * @author Ryan
 */
public class SectionManagerFrame extends javax.swing.JFrame {

    /**
     * Creates new form SectionManagerFrame
     */
    public SectionManagerFrame() {
        initComponents();


    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        jButton_Cancel = new javax.swing.JButton();
        jButton_OK = new javax.swing.JButton();
        jLabel_Title = new javax.swing.JLabel();
        jLabel_Description = new javax.swing.JLabel();
        jTextField_Title = new javax.swing.JTextField();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTextArea_Description = new javax.swing.JTextArea();
        jButton_Remove = new javax.swing.JButton();
        jButton_Add = new javax.swing.JButton();
        jButton_Edit = new javax.swing.JButton();
        jPanel_Grid = new javax.swing.JPanel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
        });

        jButton_Cancel.setText("Cancel");
        jButton_Cancel.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton_CancelMouseClicked(evt);
            }
        });

        jButton_OK.setText("OK");
        jButton_OK.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton_OKMouseClicked(evt);
            }
        });

        jLabel_Title.setText("Review Title:");

        jLabel_Description.setText("Review Description:");

        jTextArea_Description.setColumns(20);
        jTextArea_Description.setRows(5);
        jScrollPane2.setViewportView(jTextArea_Description);

        jButton_Remove.setText("Remove");

        jButton_Add.setText("Add");

        jButton_Edit.setText("Edit");

        javax.swing.GroupLayout jPanel_GridLayout = new javax.swing.GroupLayout(jPanel_Grid);
        jPanel_Grid.setLayout(jPanel_GridLayout);
        jPanel_GridLayout.setHorizontalGroup(
            jPanel_GridLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );
        jPanel_GridLayout.setVerticalGroup(
            jPanel_GridLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 268, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(122, 122, 122)
                        .addComponent(jButton_Cancel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton_OK)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jPanel_Grid, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jButton_Remove, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jButton_Add, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jButton_Edit, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel_Description)
                            .addComponent(jLabel_Title))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextField_Title))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 587, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel_Title)
                    .addComponent(jTextField_Title, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel_Description)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 196, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jButton_Add)
                        .addGap(3, 3, 3)
                        .addComponent(jButton_Edit)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton_Remove))
                    .addComponent(jPanel_Grid, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton_Cancel)
                    .addComponent(jButton_OK))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>                        

    private void jButton_CancelMouseClicked(java.awt.event.MouseEvent evt) {                                            
        // TODO add your handling code here:
        this.setVisible(false);
        this.dispose();
    }                                           

    private void jButton_OKMouseClicked(java.awt.event.MouseEvent evt) {                                        
        // TODO add your handling code here:
    }                                       

    private void formWindowOpened(java.awt.event.WindowEvent evt) {                                  
        // TODO add your handling code here:
        //ManagerDataModel newManagerDataModel = new ManagerDataModel();
        /*
        newManagerDataModel.AddColumn("Section Name");
        newManagerDataModel.AddColumn("Section Type");
        newManagerDataModel.AddColumn("# of Particles");
        newManagerDataModel.AddRow(new String[]{"Test","Test","Test"});
        */
        jTable_Sections = new JTable(5, 5);
        //jTable_Sections.setPreferredScrollableViewportSize(new Dimension(500, 500));
        jTable_Sections.setMinimumSize(new Dimension(200, 200));
        jTable_Sections.setFillsViewportHeight(true);
        jScrollPane_Sections = new JScrollPane(jTable_Sections);
        jScrollPane_Sections.setMinimumSize(new Dimension(200, 200));
        jPanel_Grid.add(jTable_Sections);
        jPanel_Grid.add(jScrollPane_Sections);
        jPanel_Grid.validate();
        jPanel_Grid.repaint();
        this.validate();
        this.pack();
        this.repaint();


    }                                 
    private JTable jTable_Sections;
    private JScrollPane jScrollPane_Sections;
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(SectionManagerFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(SectionManagerFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(SectionManagerFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(SectionManagerFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new SectionManagerFrame().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify                     
    private javax.swing.JButton jButton_Add;
    private javax.swing.JButton jButton_Cancel;
    private javax.swing.JButton jButton_Edit;
    private javax.swing.JButton jButton_OK;
    private javax.swing.JButton jButton_Remove;
    private javax.swing.JLabel jLabel_Description;
    private javax.swing.JLabel jLabel_Title;
    private javax.swing.JPanel jPanel_Grid;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTextArea jTextArea_Description;
    private javax.swing.JTextField jTextField_Title;
    // End of variables declaration                   
}

解决方案

不是GroupLayout的支持者,但对于简单的解决而言,很简单

  • 不要使用private void formWindowOpened(java.awt.event.WindowEvent evt) {将JComponents添加到已经可见的容器中,因为这是由于使用Swing GUI调整大小和闪烁而引起的

  • 对于GroupLayout必须在两个方向上都覆盖Min,Max和PreferredSize,否则将被忽略(默认情况下,请参见生成的代码)

  • JPanel在API中实现了FlowLayout,然后包装在JScollPane中的JTable在GroupLayout中丢失(确保必须有解决方案),可能与setMin,Max和PreferredSize有关.

所需的代码(我的下一点不要解决)

private void formWindowOpened(java.awt.event.WindowEvent evt) {
    jTable_Sections = new JTable(5, 5);
    jTable_Sections.setFillsViewportHeight(true);
    jScrollPane_Sections = new JScrollPane(jTable_Sections);
    jPanel_Grid.setLayout(new BorderLayout());
    jPanel_Grid.add(jScrollPane_Sections);
    this.validate();
    this.repaint();
    this.pack();
}

  • 在所有代码都由您手工制作的情况下,此代码可能约为50-70条代码行

It's Monday morning where I am, which means it's time for me to fail at Java Swing! But in all seriousness, I cannot figure out why my dynamically created JTable refuses to show itself once added to a JPanel on a JFrame, and would greatly appreciate any help in isolating this troublesome problem. As you can see from the code, I've called a dozen different methods, but can't seem to get the right one to get it to display...perhaps I am missing one?

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package energizingemerald;


import javax.swing.*;
import java.awt.Dimension;
/**
 *
 * @author Ryan
 */
public class SectionManagerFrame extends javax.swing.JFrame {

    /**
     * Creates new form SectionManagerFrame
     */
    public SectionManagerFrame() {
        initComponents();


    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        jButton_Cancel = new javax.swing.JButton();
        jButton_OK = new javax.swing.JButton();
        jLabel_Title = new javax.swing.JLabel();
        jLabel_Description = new javax.swing.JLabel();
        jTextField_Title = new javax.swing.JTextField();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTextArea_Description = new javax.swing.JTextArea();
        jButton_Remove = new javax.swing.JButton();
        jButton_Add = new javax.swing.JButton();
        jButton_Edit = new javax.swing.JButton();
        jPanel_Grid = new javax.swing.JPanel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
        });

        jButton_Cancel.setText("Cancel");
        jButton_Cancel.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton_CancelMouseClicked(evt);
            }
        });

        jButton_OK.setText("OK");
        jButton_OK.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton_OKMouseClicked(evt);
            }
        });

        jLabel_Title.setText("Review Title:");

        jLabel_Description.setText("Review Description:");

        jTextArea_Description.setColumns(20);
        jTextArea_Description.setRows(5);
        jScrollPane2.setViewportView(jTextArea_Description);

        jButton_Remove.setText("Remove");

        jButton_Add.setText("Add");

        jButton_Edit.setText("Edit");

        javax.swing.GroupLayout jPanel_GridLayout = new javax.swing.GroupLayout(jPanel_Grid);
        jPanel_Grid.setLayout(jPanel_GridLayout);
        jPanel_GridLayout.setHorizontalGroup(
            jPanel_GridLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );
        jPanel_GridLayout.setVerticalGroup(
            jPanel_GridLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 268, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(122, 122, 122)
                        .addComponent(jButton_Cancel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton_OK)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jPanel_Grid, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jButton_Remove, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jButton_Add, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jButton_Edit, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel_Description)
                            .addComponent(jLabel_Title))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextField_Title))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 587, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel_Title)
                    .addComponent(jTextField_Title, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel_Description)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 196, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jButton_Add)
                        .addGap(3, 3, 3)
                        .addComponent(jButton_Edit)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton_Remove))
                    .addComponent(jPanel_Grid, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton_Cancel)
                    .addComponent(jButton_OK))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>                        

    private void jButton_CancelMouseClicked(java.awt.event.MouseEvent evt) {                                            
        // TODO add your handling code here:
        this.setVisible(false);
        this.dispose();
    }                                           

    private void jButton_OKMouseClicked(java.awt.event.MouseEvent evt) {                                        
        // TODO add your handling code here:
    }                                       

    private void formWindowOpened(java.awt.event.WindowEvent evt) {                                  
        // TODO add your handling code here:
        //ManagerDataModel newManagerDataModel = new ManagerDataModel();
        /*
        newManagerDataModel.AddColumn("Section Name");
        newManagerDataModel.AddColumn("Section Type");
        newManagerDataModel.AddColumn("# of Particles");
        newManagerDataModel.AddRow(new String[]{"Test","Test","Test"});
        */
        jTable_Sections = new JTable(5, 5);
        //jTable_Sections.setPreferredScrollableViewportSize(new Dimension(500, 500));
        jTable_Sections.setMinimumSize(new Dimension(200, 200));
        jTable_Sections.setFillsViewportHeight(true);
        jScrollPane_Sections = new JScrollPane(jTable_Sections);
        jScrollPane_Sections.setMinimumSize(new Dimension(200, 200));
        jPanel_Grid.add(jTable_Sections);
        jPanel_Grid.add(jScrollPane_Sections);
        jPanel_Grid.validate();
        jPanel_Grid.repaint();
        this.validate();
        this.pack();
        this.repaint();


    }                                 
    private JTable jTable_Sections;
    private JScrollPane jScrollPane_Sections;
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(SectionManagerFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(SectionManagerFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(SectionManagerFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(SectionManagerFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new SectionManagerFrame().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify                     
    private javax.swing.JButton jButton_Add;
    private javax.swing.JButton jButton_Cancel;
    private javax.swing.JButton jButton_Edit;
    private javax.swing.JButton jButton_OK;
    private javax.swing.JButton jButton_Remove;
    private javax.swing.JLabel jLabel_Description;
    private javax.swing.JLabel jLabel_Title;
    private javax.swing.JPanel jPanel_Grid;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTextArea jTextArea_Description;
    private javax.swing.JTextField jTextField_Title;
    // End of variables declaration                   
}

解决方案

not GroupLayout fan, but is quite to simple fix that

  • don't to use private void formWindowOpened(java.awt.event.WindowEvent evt) { for add JComponents to already visible container, because caused with resize and flashing with Swing GUI

  • for GroupLayout must be Min, Max and PreferredSize overrode in both directions, otherwise is ignored (by default, see generated code)

  • JPanel has FlowLayout implemented in API, and then JTable wrapped in JScollPane is lost in GroupLayout (sure there must be solution) probably issue with setMin, Max and PreferredSize

required code (don't solve something with my next point)

private void formWindowOpened(java.awt.event.WindowEvent evt) {
    jTable_Sections = new JTable(5, 5);
    jTable_Sections.setFillsViewportHeight(true);
    jScrollPane_Sections = new JScrollPane(jTable_Sections);
    jPanel_Grid.setLayout(new BorderLayout());
    jPanel_Grid.add(jScrollPane_Sections);
    this.validate();
    this.repaint();
    this.pack();
}

  • this code could be about 50-70 code lines in the case that all code will be made by your hands

这篇关于JTable:将一个添加到一个JPanel,它不会显示自己的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆