Qualcuno ha una mezza idea del perchè quando mando in eseguzione questo codice il frame è della grandezza corretta mentre il jTextPane rimane piccolo.
Per chi desidera provarlo sono 3 classi..Gui che contiene il jTextPane, il main per farlo partire e WHandler per chiudere la finestra...
Help...
codice:import java.awt.*; import java.awt.event.*; import javax.swing.*; /*Create windows */ public class Gui extends JFrame { private GridBagLayout gbl; private JPanel contentPanA; public JTextPane console; private Menu menuFile; private Menu menuText; private MenuBar mb; public String font; public int style; public int size; public Gui() { super("Console"); console = new JTextPane(); console.setMargin(new Insets(5,5,5,5)); gbl = new GridBagLayout(); contentPanA = new JPanel(gbl); GridBagConstraints c = new GridBagConstraints(); /*for resize console with pannel*/ c.fill = GridBagConstraints.BOTH; c.weightx = 1.0; c.weighty = 1.0; c.gridwidth = GridBagConstraints.REMAINDER; addComponent(console, c); console.setEditable(true); /* set a textarea editable */ JScrollPane scroll = new JScrollPane(console); /* scrool bar */ addComponent(scroll, c); this.setContentPane(contentPanA); this.addWindowListener(new WHandler()); this.pack(); this.setLocation(200, 100);/*set a position of windows*/ this.setVisible(true); this.setResizable(true); } private void addComponent(JComponent jc, GridBagConstraints gbc) { gbl.setConstraints(jc, gbc); /* set a component */ contentPanA.add(jc); /* add a component*/ } } public class Main { public static void main(String[] args) { /**for assume the same aspect as the operating system**/ try{ UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception e){throw new RuntimeException(e);} Gui l ; l= new Gui(); l.setSize(400, 500); } } import java.awt.event.*; public class WHandler extends WindowAdapter { public void windowClosing(WindowEvent e) { System.exit(0); } }

Rispondi quotando