java swing怎么实现如下图片所示的布局,急急急!求大神指导。

如题所述

                final JFrame frame = new JFrame("Form Example");
                
                final JButton addButton = new JButton("Add");
                final JButton deleteButton = new JButton("Delete");
                final JButton modifyButton = new JButton("Modify");                
                final JButton closeButton = new JButton("Close");
                final Box topbox = Box.createHorizontalBox();
                final Box bottomBox = Box.createHorizontalBox();
                
                final DefaultTableModel model = new DefaultTableModel();
                model.addColumn("\u25A1");
                model.addColumn("名称");
                model.addColumn("类名称");
                model.setRowCount(5);
                final JTable classTable = new JTable(model);
            
                topbox.add(Box.createHorizontalStrut(5));
                topbox.add(addButton);
                topbox.add(Box.createHorizontalStrut(5));
                topbox.add(deleteButton);   
                topbox.add(Box.createHorizontalStrut(5));
                topbox.add(modifyButton);
                topbox.add(Box.createHorizontalGlue());
                topbox.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
                bottomBox.add(Box.createHorizontalGlue());
                bottomBox.add(closeButton);
                bottomBox.add(Box.createHorizontalStrut(5));
                bottomBox.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));

                frame.add(topbox, BorderLayout.PAGE_START);
                frame.add(new JScrollPane(classTable));
                frame.add(bottomBox, BorderLayout.PAGE_END);
                frame.pack();
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.setVisible(true);

温馨提示:内容为网友见解,仅供参考
第1个回答  2016-05-23
可以使用绝对定位 ,不要布局,然后 setBounds()
第2个回答  2016-05-23
绝对布局,会不会??
相似回答
大家正在搜