0
我無法使用setPreferredSize函數設置動態創建的JPanel大小。還有其他方法嗎?如何設置動態創建的jpanel的高度?
main_panel.removeAll();
main_panel.revalidate();
main_panel.repaint();
panel = new JPanel[100];
Login.session = Login.sessionfactory.openSession();
Login.session.beginTransaction();
String select_n_p_4 = "select a.triage_id from PC_TRIAGE_MASTER_POJO a";
org.hibernate.Query query1 = Login.session.createQuery(select_n_p_4);
List l3 = query1.list();
Iterator it3 = l3.iterator();
while (it3.hasNext()) {
Object a4 = (Object) it3.next();
int f = (int) a4;
main_panel.setLayout(new GridLayout(0, 1, 1, 10));
panel[ind] = new JPanel();
panel[ind].setPreferredSize(new Dimension(10, 10));
panel[ind].setBorder(triage_boder);
count++;
main_panel.add(panel[ind]);
main_panel.revalidate();
main_panel.repaint();
ind++;
}
讓我們從'[應該避免使用Java Swing中的set(Preferred | Maximum | Minimum)尺寸方法?](http://stackoverflow.com/questions/7229226/should-i-avoid-the- use-of-setpreferredmaximumminimumsize-methods-in-java-swi)'然後問什麼'main_panel'用於佈局管理器 – MadProgrammer 2015-03-25 04:05:16
爲什麼你不能? – Mordechai 2015-03-25 04:05:58