问题描述
- java GridBagLayout 表格内容不显示,,而且会自动居中
-
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.table.DefaultTableModel;public class KuCunPanDianPanel extends JPanel{
private JTextField pandianyuan;
private JTextField pandianshijian;
private JTextField pinzhongshu;//private DefaultTableModel model = new DefaultTableModel();//private JTable table = new JTable(model);private JScrollPane sp_table;public KuCunPanDianPanel(){ super(); setBounds(10 10 460 300); setLayout(new GridBagLayout()); setVisible(true); setupComponet(new JLabel("" 盘 点 员:"") 0 0 1 0 false); pandianyuan = new JTextField(""Tsoft""); // 定位盘点员文本框 setupComponet(pandianyuan 1 0 1 100 true); setupComponet(new JLabel("" 盘点时间:"") 2 0 1 0 false); pandianshijian = new JTextField(""2010-5-18 16:40:41""); // ·定位盘点时间文本框 setupComponet(pandianshijian 3 0 1 150 true); setupComponet(new JLabel("" 品 种 数:"") 4 0 1 0 false); pinzhongshu = new JTextField(""1""); // 定位品种数文本框 setupComponet(pinzhongshu 5 0 1 100 true); String[] name={""商品名称""商品编号""供应商""产地""单位""规格""单价""数量""包装""}; //String[] columnNames = {""Product""Number of Boxes""Price""}; //Object data[][] = {{ ""小芳""142321"" }{ ""小芳""142321"" } }; Object[][] data = { {""计算机""sp1001""小公司""山东青岛""台"""new Double(10000.000) new Integer(10)箱""} }; JTable table = new JTable(dataname); //table.setPreferredScrollableViewportSize(new Dimension(300 80)); //创建一个滚动面板,包含表格 sp_table = new JScrollPane(table); setupComponet(sp_table 0 1 10 400 true);}private void setupComponet(JComponent component int gridx int gridy int gridwidth int ipadx boolean fill) { final GridBagConstraints gridBagConstrains = new GridBagConstraints(); gridBagConstrains.gridx = gridx; gridBagConstrains.gridy = gridy; gridBagConstrains.insets = new Insets(5 1 3 1); if (gridwidth > 1) gridBagConstrains.gridwidth = gridwidth; if (ipadx > 0) gridBagConstrains.ipadx = ipadx; if (fill) gridBagConstrains.fill = GridBagConstraints.HORIZONTAL; add(component gridBagConstrains);}
public void initComboBox() {
}
}
解决方案
用这个布局不行吧,你可以换个布局试试,分成两部分,盘点员那部分用flowlayout,整体使用borderlayout,你试试看
时间: 2024-11-29 11:02:56