ciao!
ho qualche problema nel settare le dimensioni in alcuni componenti swing.
non riesco bene a capire cosa mi sfugge:
in pratica le due text field e il bottone si prendono comunque le massime dimensioni possibili.codice:public class MainWindow extends JFrame { private JPanel mainPanel; private JTextField txtSource; private JTextField txtDestination; private JButton btnStart; private int generalW = 505; private int generalH = 20; public MainWindow() { mainPanel = new JPanel(new BorderLayout()); txtSource = new JTextField(); txtSource.setPreferredSize(new Dimension(generalW, generalH)); txtDestination = new JTextField(); txtDestination.setPreferredSize(new Dimension(generalW, generalH)); btnStart = new JButton("Start"); btnStart.setPreferredSize(new Dimension(generalW, generalH)); mainPanel.add(txtSource, BorderLayout.NORTH); mainPanel.add(txtDestination, BorderLayout.CENTER); mainPanel.add(btnStart, BorderLayout.SOUTH); setLayout(new BorderLayout()); getContentPane().add(mainPanel, BorderLayout.CENTER); setPreferredSize(new Dimension(500, 100)); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setResizable(false); pack(); setLocationRelativeTo(null); } }
come dovrei fare??

Rispondi quotando
