我在 JScrollPane 中有一个 JTable。我希望最小宽度在 600 左右,因为它是一张宽桌子。我尝试在表格、滚动窗格和面板上设置最小尺寸。大小根本没有改变,我错过了什么?很难用谷歌搜索这个,因为出现的只是如何设置列的宽度。
这是代码:
class SearchResults extends JPanel {
/**
* Create the panel.
*/
public SearchResults() {
setMinimumSize(new Dimension(640, 480));
String[][] data= new String[][] {
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, "VIEW BUTTON"},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, "VIEW BUTTON"}};
String[] col = new String[] {
"Last Name", "First Name", "Middle Initial", "Phone Number", "Email", "Project Title", "Project Description", "Amount", "Date Approved", "Date Completed", "College", "Faculty Mentor Name", "Co Grantee", "Major", "Travel Required", "Travel Purpose", "Travel Cost", "Travel Start Date", "Travel End Date", "View"};
JTable table = new JTable(data,col);
table.setMinimumSize(new Dimension(600,200));
JTableHeader header = table.getTableHeader();
JScrollPane pane = new JScrollPane(table);
pane.setMinimumSize(new Dimension(600, 23));
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
add(pane);
}
}
这里是我将它添加到 JFrame 的地方:
public class Test extends JFrame
{
public static void main(String[] args)
{
Test test = new Test();
test.run();
}
public Test()
{
super("JAVA TEST!");
}
private void run()
{
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
SearchResults resultsPanel = new SearchResults();
resultsPanel.setMinimumSize(new Dimension(600,200));
add(resultsPanel);
setSize(800,600);
setVisible(true);
}
}