Non lo fa in automatico? Prova questo.
codice:import java.awt.BorderLayout; import java.awt.Color; import java.awt.Container; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JToolBar; public class NewClass extends JFrame{ JFrame f; public NewClass() { Container content = this.getContentPane(); //Faccio una toolbar JToolBar toolBar = new JToolBar(""); toolBar.add(new JButton("a")); toolBar.add(new JButton("b")); content.add(toolBar, BorderLayout.NORTH); //Faccio un pannello con bottone per l'evento ridimensionamento JPanel pane = new JPanel(); pane.setBackground(Color.RED); JButton b = new JButton("Resize!"); f = this; b.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { f.setSize(1000, 1000); } }); pane.add(b); content.add(pane,BorderLayout.CENTER); //Visualizzo la finestra this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); this.setSize(100, 100); this.setVisible(true); } public static void main(String[] args) { new NewClass(); } }

Rispondi quotando