如何調整JWindow
的高度從JButton
行動(我試過setSize和重繪,但它不起作用)?如何在Java中使用JButton動作調整JWindow的寬度和高度?
public class Gui extends JWindow implements KeyListener
{
public static Gui mystatic;
private static JPanel panelBgImg;
private final Dimension screen;
public static int w = 0;
public static int h = 0;
public void paintComponent(Graphics g)
{
}
public Dimension getPreferredSize()
{
return new Dimension(100, h);
}
public Gui()
{
....
/* Button 1 */
JButton jb2 = new JButton("")
{
public Dimension getPreferredSize()
{
return new Dimension(50,50);
}
};
jb2.setOpaque(false);
jb2.setContentAreaFilled(false);
jb2.setBorderPainted(false);
jb2.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
h = 100;
/* HERE i am trying to resize the JWindow itself but not working
return new Dimension(100, h); */
mystatic.setSize(screen.width, 100);
mystatic.repaint();
}
});
...
}
請告訴我SSCCE的完整形式,大多數人都使用這個縮寫。我將被迫。問候 – 2011-12-28 09:21:34
http://sscce.org/是虛擬的rulles( - :由他的陛下設計:-) @Andrew Thompson, – mKorbel 2011-12-28 09:31:36
Thankyou的信息,只是在你的代碼中捕捉到了這個縮寫。好像對我真的有幫助。 Registers – 2011-12-28 09:38:10