Pagina 2 di 2 primaprima 1 2
Visualizzazione dei risultati da 11 a 14 su 14
  1. #11
    Utente di HTML.it L'avatar di andbin
    Registrato dal
    Jan 2006
    residenza
    Italy
    Messaggi
    18,284
    Originariamente inviato da PazZII
    se mi fa un esempio
    Un semplice esempio di finestra che ha: due pulsanti al fondo del frame, disposti in fila orizzontale, che si spartiscono la larghezza del frame al 50% e una text area che occupa tutto il resto del frame.

    codice:
    import java.awt.*;
    import javax.swing.*;
    
    public class TestFrame extends JFrame {
        private JTextArea textArea;
        private JButton button1;
        private JButton button2;
    
        public TestFrame() {
            super("Test");
            setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    
            textArea = new JTextArea();
            JScrollPane scrollPane = new JScrollPane(textArea);
            scrollPane.setPreferredSize(new Dimension(300, 200));
    
            button1 = new JButton("1");
            button2 = new JButton("2");
    
            JPanel buttonsPanel = new JPanel(new GridLayout(1, 2));
            buttonsPanel.add(button1);
            buttonsPanel.add(button2);
    
            Container contentPane = getContentPane();
            contentPane.add(scrollPane, BorderLayout.CENTER);
            contentPane.add(buttonsPanel, BorderLayout.SOUTH);
    
            pack();
        }
    
        public static void main(String[] args) {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    new TestFrame().setVisible(true);
                }
            });
        }
    }
    Andrea, Senior Java developerSCJP 5 (91%) • SCWCD 5 (94%)
    Java Versions Cheat Sheet

  2. #12
    e nel caso di un jinternaframe?

    Intanto faccio dei test con questo codice mumblemumble

  3. #13
    Utente di HTML.it L'avatar di andbin
    Registrato dal
    Jan 2006
    residenza
    Italy
    Messaggi
    18,284
    Originariamente inviato da PazZII
    e nel caso di un jinternaframe?
    codice:
    import java.awt.*;
    import javax.swing.*;
    
    public class TestFrame extends JFrame {
        public TestFrame() {
            super("Test");
            setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
            setSize(500, 400);
    
            JDesktopPane desktopPane = new JDesktopPane();
            desktopPane.add(new IntFrame());
    
            getContentPane().add(desktopPane, BorderLayout.CENTER);
        }
    
        public static void main(String[] args) {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    new TestFrame().setVisible(true);
                }
            });
        }
    }
    
    
    class IntFrame extends JInternalFrame {
        private JTextArea textArea;
        private JButton button1;
        private JButton button2;
    
        public IntFrame() {
            super("Test", true, true, true, true);
            setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    
            textArea = new JTextArea();
            JScrollPane scrollPane = new JScrollPane(textArea);
            scrollPane.setPreferredSize(new Dimension(300, 200));
    
            button1 = new JButton("1");
            button2 = new JButton("2");
    
            JPanel buttonsPanel = new JPanel(new GridLayout(1, 2));
            buttonsPanel.add(button1);
            buttonsPanel.add(button2);
    
            Container contentPane = getContentPane();
            contentPane.add(scrollPane, BorderLayout.CENTER);
            contentPane.add(buttonsPanel, BorderLayout.SOUTH);
    
            pack();
            setVisible(true);
        }
    }
    Come puoi vedere, cambia relativamente poco. C'è solo di mezzo un JDesktopPane che ora occupa lui tutto il content pane del JFrame mentre tutto il setup di prima del JFrame l'ho spostato in una classe separata che ora estende JInternalFrame e in cui cambia davvero poco (i flag a true nella invocazione di super() per renderlo ridimensionabile/chiudibile ecc..., il default close operation che non può essere più EXIT_ON_CLOSE e il setVisible al fondo che invece serve).
    Andrea, Senior Java developerSCJP 5 (91%) • SCWCD 5 (94%)
    Java Versions Cheat Sheet

  4. #14
    Perfetto
    anche io ero arrivato allo stesso risultato maneggiando l'esempio nei tutorial Java.
    AHhhhhhhh perfetto ora ho un esempio base dal quale ho già capito diverse cose.
    Ti ringrazio tantissimo per l'aiuto e per la pazienza
    Ciao!!!

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2026 vBulletin Solutions, Inc. All rights reserved.