JFrame:固定宽度但动态高度
问题描述:
有没有什么方法可以设置JFrame的宽度固定,但JFrame动态的高度是多少?举一个例子,JFrame:固定宽度但动态高度
width = 1200
Height = will be based on number of elements
换句话说
width = 1200
Height = pack()
请帮助!
答
使用恒定的宽度和高度为一个变量,然后用the regular setPreferredSize method
+0
我敢肯定,不要停止框架的大小(宽度明智) - 这是我如何阅读问题。另外,我们通常不鼓励使用setPreferredSize – MadProgrammer 2013-03-19 09:30:33
我觉得你最好的选择是通过覆盖它的'getPreferredSize'方法 – MadProgrammer 2013-03-19 07:43:00
不要设置限制内容窗格的宽度固定大小。请看这[问题](http://stackoverflow.com/questions/7229226/should-i-avoid-the-use-of-setpreferredmaximumminimumsize-methods-in-java-swi) – Amarnath 2013-03-19 07:53:19
也考虑'BorderLayout.EAST'或'BorderLayout.WEST'。 – trashgod 2013-03-19 10:50:07