[英]JTable not showing after adding to JScrollPane?
我有一個很好的JTable。 如果將表放在JScrollPane中,它將不再顯示。 為什么不? 我想將兩個表都添加到自己的JScrollPane中。 在這里,我只在其中嘗試向第一個表添加JScrollPane的代碼:
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 1000, 800);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
JProgressBar progressBar = new JProgressBar();
progressBar.setBounds(50, 68, 700, 14);
frame.getContentPane().add(progressBar);
JTextPane txtpnAutomotiveHmi = new JTextPane();
txtpnAutomotiveHmi.setText("Automotive HMI");
txtpnAutomotiveHmi.setBounds(362, 21, 205, 20);
frame.getContentPane().add(txtpnAutomotiveHmi);
testcase_table = new JTable();
testcase_table.setBounds(50, 125, 350, 426);
JScrollPane scroll_testcase = new JScrollPane(testcase_table);
frame.getContentPane().add(scroll_testcase);
teststep_table = new JTable();
teststep_table.setBounds(399, 125, 350, 426);
frame.getContentPane().add(teststep_table);
}
謝謝。
不要設置空布局。 它不是“默認布局”,也不是“最簡單的實現”。 實際上,很難做到正確。
JFrame
默認使用BorderLayout
。 添加JProgressBar
與BorderLayout.NORTH
, JTextPane
與BorderLayout.SOUTH
和JScrollPane
與BorderLayout.CENTER
。 刪除所有setBounds
。 組件將出現。 如果您需要以某種復雜的方式放置它們,請閱讀GridBagLayout
。
定義表的大小,並為滾動窗格設置相同的大小。
scrollPane.setSize(table.getSize());
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.