Errore mio.
Il PreferredSize va, ovviamente, impostato sul JScrollPane e non sulla JTextArea.
E' il JScrollPane, infatti, che viene aggiunto alla finestra, non la JTextArea... di conseguenza, è il JScrollPane che viene influenzato dal LayoutManager e non la JTextArea.
Riposto l'esempio corretto.
codice:import java.awt.*; import javax.swing.*; public class AreaSopra extends JFrame { private JTextArea txt; public AreaSopra() { Container c = getContentPane(); c.setLayout( new BorderLayout() ); txt = new JTextArea(); JScrollPane jsp = new JScrollPane( txt ); jsp.setPreferredSize( new Dimension(800, 80) ); c.add(jsp, BorderLayout.NORTH); setTitle("Test TextArea NORTH"); setSize(800, 600); setDefaultCloseOperation( EXIT_ON_CLOSE ); setVisible( true ); } public static void main(String[] args) { AreaSopra a = new AreaSopra(); } }



Rispondi quotando