我在找一个覆盖Teamspeak3.
问题是,我不能像我想的那样调整一个JTable
截图:
我希望表(屏幕上有两个名字)位于左上角
这是我的代码:
public void setPanelContent(Object[][] clientList, Object[][] msgList)
{
JPanel jp_ = new JPanel();
jp_.setLayout(new GridBagLayout());
GridBagConstraints g = new GridBagConstraints();
g.gridx = 1;
//g.fill = GridBagConstraints.HORIZONTAL;
g.anchor = GridBagConstraints.FIRST_LINE_START;
g.weightx = 1;
String title[] = {"A", "B"};
JTable tableau = new JTable(clientList, title);
tableau.setTableHeader(null);
tableau.setRowHeight(20);
tableau.setShowGrid(false);
tableau.setEnabled(false);
// tableau.setOpaque(false);
((DefaultTableCellRenderer)tableau.getDefaultRenderer(Object.class)).setOpaque(false);
tableau.getColumn("A").setMaxWidth(30);
tableau.getColumn("B").setMinWidth(210);
// tableau.getColumn("B").setMaxWidth(520);
tableau.getColumnModel().getColumn(0).setCellRenderer(new ImageRenderer());
jp_.add(tableau, g);
jp_.setBackground(Color.CYAN); // for test
jp_.setPreferredSize(new Dimension(jp.getWidth(), jp.getHeight()));
jp.removeAll();
jp.invalidate();
jp.add(jp_);
jp.updateUI();
this.repaint();
}发布于 2014-03-22 17:05:56
尝试在窗口顶部( JPanel ) (BorderLayout.NORTH)中创建一个JPanel,这是您刚刚用BorderLayout WEST创建的JPanel中的一个新JPanel,然后在最后一个JPanel中添加JTable。
发布于 2014-03-21 22:37:15
GridBagLayout垂直空间),则可以通过添加以下内容来扩展JTable高度:
g.fill =GridBagConstraints.VERTICAL,g.weighty = 1;https://stackoverflow.com/questions/22570447
复制相似问题