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