【问题标题】:Resizing JTable that's in a JPanel调整 JPanel 中的 JTable 的大小
【发布时间】:2016-11-05 11:33:52
【问题描述】:

这是我的代码 JTabel,位于 JPanel 中,我目前遇到了调整大小的问题。它只是占据了 GUI 的西部,我试图让它占据左下角而不是一直向上。这是我的代码:

public void table(JFrame f) 
{

  String[] columnNames = {"First Name", "Last Name"};

  Object[][] players = {
                    {"John", "Doe"},
                    {"Steve", "White"}
  };

  JTable table = new JTable(players, columnNames);
  JScrollPane scrollPane = new JScrollPane(table);

  table.setFillsViewportHeight(true); 

  JPanel container = new JPanel();
  container.setPreferredSize(new Dimension(50,300)); //This seems very wrong
  container.setLayout(new BorderLayout());
  container.add(table.getTableHeader(), BorderLayout.PAGE_START);
  container.add(table, BorderLayout.WEST);

  f.add(container);

  f.revalidate();

【问题讨论】:

    标签: java jframe jtable jpanel


    【解决方案1】:

    在这行代码

      container.add(table.getTableHeader(), BorderLayout.PAGE_START);
    

    你这么说,BorderLayout.PAGE_START。而不是 PAGE_START,您应该在下图的帮助下将其定义到您想要放置组件的位置。

    更多信息可以阅读this

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-12-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-01
      • 2013-08-04
      相关资源
      最近更新 更多