tutorials.de Buch-Aktion 05/2012
ERLEDIGT
NEIN
ANTWORTEN
2
ZUGRIFFE
746
EMPFEHLEN
  • An Twitter übertragen
  • An Facebook übertragen
AUF DIESES THEMA
ANTWORTEN
  1. #1
    Maddili Maddili ist offline Mitglied Silber
    Registriert seit
    Feb 2010
    Beiträge
    65
    Hallo,

    ich bin im Moment daran, mich an einer (einfachen) GUI zu versuchen.

    Soll ungefähr SO aussehen:

    --------------------------------------------------
    * MenuBar
    --------------------------------------------------
    * * *
    * * *
    *----- Pane 1------||----- Pane 2 ------- *
    * * *
    -------------------Splitpane----------------------
    -Tab1|Tab2|Tab3|Tab4|-----------------------
    * *
    * TabbedPane *
    * *
    * *



    Nun, leider bekomme ich das überhaupt nicht hin. Habe auch einen VisualEditor, wo ich dachte ich könnte das mit Drag&Drop einfach gestalten... ..aber nix da!

    Einzelne Dinge ****en schon, aber das Zusammenspiel überhaupt nicht.
    Menubar kann ich adden (aus eigener Klasse), aber nicht die Splitpane. Wenn die Splitpane geaddet ist, kann ich sie nicht verschieben... usw. usw.

    Erstmal zum Verständnis:

    Lege ich über den Main Frame eine JPane (JContentpane) und adde die anderen Panes zu der Contentpane?
    Ist die Reihenfolge relevant?
    In den Tabs sollen verschiedene Darstellungen (Tabellen, Text usw.) aus verschiedenen VisualClasses rein. Kein Prob, oder?

    Kann mir bitte jemand helfen? Muss ja keiner für mich erstellen, aber die GUI-Basics "erklären".
    Hab ja schon so viel gelesen (und bin kein Java-Neuling - hab nur noch keine GUI erzeugt!), aber komme irgendwie nicht "dahinter".

    Grüße und schöne Woche,
    Maddin
     

  2. #2
    Maddili Maddili ist offline Mitglied Silber
    Registriert seit
    Feb 2010
    Beiträge
    65
    BITTE BITTE**********

    Hier meine Klassen: Keine ahnung, warum außer der Menubar NICHTS angezeigt wird!!

    Code java:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    
    public class Main extends JFrame implements ComponentListener {
     
        private static final long serialVersionUID = 1L;
        private JScrollPane jScrollPane = null;  
        public static Output o;
        public static JFrame frame = new JFrame("");  
        public static BasicWindowMonitor b;
        public static Main m1;
     
     
        
        public static void main(String[] args) {
            m1 = new Main();
        }
     
        /**
         * This is the default constructor
         */
        public Main() {
            this.setPreferredSize(new Dimension(1280, 998));
            this.setMinimumSize(new Dimension(780, 580));
            this.pack();
            this.addComponentListener(this);
            this.setTitle("Masterplan - Tool");
            this.setJMenuBar(new Menubar());
            this.setDefaultCloseOperation(0);
            b = new BasicWindowMonitor();
            this.add(getJScrollPane());
            this.addWindowListener(b);
            o = new Output();
            jScrollPane.setViewportView(o);
            jScrollPane.getViewport().setViewSize(new Dimension(1280, 1000));
            jScrollPane.setAutoscrolls(true);
            this.setVisible(true);
     
     
            this.setContentPane(getJScrollPane());
            this.setTitle("LEck mich doch am *****!");
        }
     
        /**
         * This method initializes jContentPane
         *
         * @return javax.swing.JPanel
         */
        private JScrollPane getJScrollPane() {
            if (jScrollPane == null) {
                jScrollPane = new JScrollPane();
                jScrollPane
                        .setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
                jScrollPane
                        .setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
            }
            return jScrollPane;
        }
     
        public void componentHidden(ComponentEvent e) {
            // TODO Auto-generated method stub
     
        }
     
        public void componentMoved(ComponentEvent e) {
            // TODO Auto-generated method stub
     
        }
     
        public void componentResized(ComponentEvent e) {
            double breite = e.getComponent().getSize().getWidth();
            double hoehe = e.getComponent().getSize().getHeight();
            double breitemin = frame.getMinimumSize().getWidth();
            double hoehemin = frame.getMinimumSize().getHeight();
            if (breite < breitemin) {
                frame.setSize(frame.getMinimumSize());
            } else if (hoehe < hoehemin) {
                frame.setSize(frame.getMinimumSize());
            }
        }
     
        public void componentShown(ComponentEvent e) {
            // TODO Auto-generated method stub
     
        }
     
    }


    Und hier noch meine Klasse Output:

    Code java:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    
     
    public class Output extends JPanel implements MouseListener,
    ActionListener, KeyListener {
     
        public static JSplitPane jSplitPane = null;
        public static JPanel BottomPane = null;
        public static JPanel Top = null;
        public static JScrollPane ScrollPaneOben = null;
        public static JPanel MittelPanel = null;
        public static JPanel PanelTable = null;
        public static JScrollPane ScrollPaneUnten = null;
        public static JTabbedPane TPD = null;
        public static JToolBar ToolBarUnten = null;
        public static JPanel ToolBarPanel = null;
     
        public static BorderLayout b;
     
        /**
         * This is the default constructor
         */
        public Output() {
            super();
            //initialize();
     
        }
     
        /**
         * This method initializes this
         *
         * @return void
         */
        private void initialize() {
     
            try{
                this.setSize(1200, 980);
                this.setLayout(null);
                this.add(BottomPane);
            }catch (Exception e) {
                System.out.println("34qökorhtq-");
            }
     
            try {
                UIManager.setLookAndFeel("com.birosoft.liquid.LiquidLookAndFeel");
                SwingUtilities.updateComponentTreeUI(this);
            } catch (UnsupportedLookAndFeelException e) {
                System.out.println("UnsupportedLookAndFeelException");
            } catch (ClassNotFoundException e) {
                System.out.println("ClassNotFoundException");
            } catch (InstantiationException e) {
                System.out.println("InstantiationException");
            } catch (IllegalAccessException e) {
     
            }
     
            this.add(jSplitPane, null);
    //      PanelTable.add(suchPanel.getSearchPanel);
    //      SearchPanel.tableView.addMouseListener(this);
    //      SearchPanel.tableView.addKeyListener(this);
     
    //      sd = new StammdatenNew();
            TPD.addTab("MASTER", null);
     
     
        }
     
        /**
         * This method initializes jSplitPane
         *
         * @return javax.swing.JSplitPane
         */
        public JSplitPane getJSplitPane() {
            if (jSplitPane == null) {
                jSplitPane = new JSplitPane();
                jSplitPane.add(Top);
                jSplitPane.add(BottomPane);
            }
            return jSplitPane;
        }
     
        /**
         * This method initializes BottomPane
         *
         * @return javax.swing.JPanel
         */
        private JPanel getBottomPane() {
            if (BottomPane == null) {
                BottomPane = new JPanel();
                b = new BorderLayout();
                BottomPane.setLayout(b);
                BottomPane.add(getScrollPaneUnten(), BorderLayout.CENTER);
                BottomPane.add(getToolBarUnten(), BorderLayout.NORTH);
            }
            return BottomPane;
        }
        /**
         * This method initializes Top
         *
         * @return javax.swing.JPanel
         */
        public JPanel getTop() {
            if (Top == null) {
                Top = new JPanel();
                Top.setLayout(new BorderLayout());
                Top.add(getScrollPaneOben(), BorderLayout.CENTER);
     
            }
            return Top;
        }
     
        /**
         * This method initializes ScrollPaneOben
         *
         * @return javax.swing.JScrollPane
         */
        public JScrollPane getScrollPaneOben() {
            if (ScrollPaneOben == null) {
                ScrollPaneOben = new JScrollPane();
                ScrollPaneOben
                        .setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
                ScrollPaneOben.setViewportView(getMittelPanel());
            }
            return ScrollPaneOben;
        }
     
        /**
         * This method initializes MittelPanel
         *
         * @return javax.swing.JPanel
         */
        public JPanel getMittelPanel() {
            if (MittelPanel == null) {
    /*          lbldberrorIcon = new JLabel();
                lbldberrorIcon.setBounds(new Rectangle(27, 293, 24, 38));
                lbldberrorIcon.setIcon(new ImageIcon("http://www.tutorials.de/images/database_delete.png"));
                lbldberrorIcon.setDisplayedMnemonic(KeyEvent.VK_UNDEFINED);
                lbldbleer = new JLabel();
                lbldbleer.setBounds(new Rectangle(50, 293, 304, 38));
                lbldbleer.setForeground(java.awt.Color.red);
                lbldbleer.setFont(new Font("Georgia", Font.BOLD, 11));
                lbldbleer.setText(xml.getLabel("errordbleer"));
        */      MittelPanel = new JPanel();
                MittelPanel.setLayout(null);
                MittelPanel.add(getPanelTable(), null);
    //          MittelPanel.add(getAnzahlDatensaetze(), null);
    //          MittelPanel.add(getSearchfor(), null);
    //          MittelPanel.add(lbldbleer, null);
    //          MittelPanel.add(lbldberrorIcon, null);
    //          MittelPanel.add(getScverlauf(), null);
    //          MittelPanel.add(getVerlauf(), null);
                MittelPanel
                .addComponentListener(new java.awt.event.ComponentAdapter() {
                    @Override
                    public void componentResized(
                            java.awt.event.ComponentEvent e) {
                        component_action();
                    }
                });
            }
            return MittelPanel;
        }
     
     
        public static void component_action() {
            PanelTable.setBounds(new Rectangle(353, 3, 526,
                    MittelPanel.getHeight() - 17));
    /*      SearchPanel.searchPanel.setPreferredSize(new java.awt.Dimension(500,
                    MittelPanel.getHeight() - 22));
            SearchPanel.scrollpane.setPreferredSize(new java.awt.Dimension(505,
                    MittelPanel.getHeight() - 25));
            scverlauf.setBounds(new Rectangle(890, 70, 345,
                    MittelPanel.getHeight() - 86));
    */
        }
     
     
     
     
     
        /**
         * This method initializes PanelTable
         *
         * @return javax.swing.JTable
         */
        public JPanel getPanelTable() {
            if (PanelTable == null) {
                PanelTable = new JPanel();
                PanelTable.setLayout(new GridBagLayout());
                PanelTable.setBounds(new Rectangle(353, 3, 526, 390));
     
            }
            return PanelTable;
        }
     
        /**
         * This method initializes ScrollPaneUnten
         *
         * @return javax.swing.JScrollPane
         */
        public JScrollPane getScrollPaneUnten() {
            if (ScrollPaneUnten == null) {
                ScrollPaneUnten = new JScrollPane();
                ScrollPaneUnten
                        .setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
                ScrollPaneUnten.setViewportView(getTPD());
            }
            return ScrollPaneUnten;
        }
     
        /**
         * This method initializes TPD
         *
         * @return javax.swing.JTabbedPane
         */
        public JTabbedPane getTPD() {
            if (TPD == null) {
                TPD = new JTabbedPane();
            }
            return TPD;
        }
     
        /**
         * This method initializes ToolBarUnten
         *
         * @return javax.swing.JToolBar
         */
        public JToolBar getToolBarUnten() {
            if (ToolBarUnten == null) {
                ToolBarUnten = new JToolBar("Toolbar");
                ToolBarUnten.setOrientation(JToolBar.VERTICAL);
                ToolBarUnten.setBorder(null);
                ToolBarUnten.setToolTipText("tbartext");
                ToolBarUnten.setFloatable(false);
                ToolBarUnten.add(getToolBarPanel());
                ToolBarUnten.add(getJSplitPane());
                ToolBarUnten.setRollover(true);
            }
            return ToolBarUnten;
        }
     
        /**
         * This method initializes ToolBarPanel
         *
         * @return javax.swing.JPanel
         */
        public JPanel getToolBarPanel() {
            if (ToolBarPanel == null) {
                ToolBarPanel = new JPanel();
                ToolBarPanel.setLayout(new FlowLayout());
                ToolBarPanel.setPreferredSize(new Dimension(120, 40));
        /*      ToolBarPanel.add(getLetzte(), null);
                ToolBarPanel.add(getNaechster(), null);
                ToolBarPanel.add(getZurueck(), null);
                ToolBarPanel.add(getVor(), null);
                ToolBarPanel.add(getNeu(), null);
                ToolBarPanel.add(getAendern(), null);
                ToolBarPanel.add(getLoeschen(), null);
                ToolBarPanel.add(getDrucken(), null);
                ToolBarPanel.add(getPdfout(), null);
                ToolBarPanel.add(getEnde(), null);
        */  }
            return ToolBarPanel;
        }
    }
     
    // Hier kommen noch die ganzen Events. Poste ich mal nicht mit....





    Findet bitte irgendwer den Fehler. Ich verliere langsam die Nerven.

    mfg
    Maddin
     

  3. #3
    Tsunamii Tsunamii ist offline Mitglied Silber
    Registriert seit
    Jul 2009
    Beiträge
    75
    Hi,
    habe mir jetzt deinen code nicht weiter angeschaut sondern habe mal versucht deine gewollte Gui so einfach wie möglich nachzubauen.
    Hier mal der Code dazu:
    Code :
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    
    package guiTesting;
     
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.GridLayout;
     
    import javax.swing.JFrame;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    import javax.swing.JPanel;
    import javax.swing.JSplitPane;
    import javax.swing.JTabbedPane;
     
    public class Gui extends JFrame {
     
        private static final long serialVersionUID = 1L;
        
        private JMenuBar menubar;
        private JMenu menu;
        private JMenuItem item;
     
        private JPanel oben;
        private JPanel links;
        private JPanel rechts;
     
        private JSplitPane splitPane;
     
        private JTabbedPane tabs;
        private JPanel tab1;
        private JPanel tab2;
     
        public Gui() {
            _init();
            _build();
            _show();
        }
     
        /**
         * Initialisierung aller Elemente
         */
        private final void _init() {
            setLayout(new BorderLayout());
     
            // MENU
            menubar = new JMenuBar();
            menu = new JMenu("Datei");
            item = new JMenuItem("Beenden");
     
            // OBERE PANELS
            oben = new JPanel(new GridLayout(1, 2));
            links = new JPanel();
            rechts = new JPanel();
     
            // UNTERE TABS
            tabs = new JTabbedPane();
            tab1 = new JPanel();
            tab2 = new JPanel();
     
            // JSPLITPANE
            splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, oben, tabs);
        }
     
        /**
         * Zusammenbauen der Oberfläche
         */
        private final void _build() {
            // MENU
            menubar.add(menu);
            menu.add(item);
            setJMenuBar(menubar);
     
            // OBERE PANELS
            links.setBackground(Color.WHITE); // Zum Sichtbarmachen der beiden
            rechts.setBackground(Color.BLACK); // Panels
            oben.add(links);
            oben.add(rechts);
     
            // UNTERE TABS
            tabs.add("Tab 1", tab1);
            tabs.add("Tab 2", tab2);
     
            // SPLITPANE
            add(splitPane, BorderLayout.CENTER);
        }
     
        /**
         * Oberfläche sichtbar machen
         */
        private final void _show() {
            setSize(500, 500);
            setMinimumSize(getSize());
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setLocationRelativeTo(null); // lässt Frame in der Mitte erscheinen
            setVisible(true);
     
            splitPane.setDividerLocation(0.5);// funktioniert erst wenn SplitPane
                                                // sichtbar ist
        }
     
        public static void main(String[] args) {
            new Gui();
        }
     
    }

    Vorgehensweiße:
    - Erstellen des Menüs
    - Erstellen der 2 Panels oben und anschließendes Hinzufügen auf ein Panel mit GridLayout(zum nebeneinander anordnen)
    - Ertellen der Tabs inklusive TabbedPane für unten
    - Erstellen der SplitPane mit den benötigten Parametern
    - nötige Einstellungen für Frame(Größe, Position ...) treffen
    - Frame sichtbar machen
    - Divider der SplitPane in die Mitte setzen

    Ich hoffe ich konnte dir damit weiterhelfen, wenn noch Fragen sind kannst du die gerne stellen
     

Ähnliche Themen

  1. DTP Anfänger
    Von Salia im Forum Desktop Publishing (DTP)
    Antworten: 6
    Letzter Beitrag: 28.09.06, 14:09
  2. jTable in TabbedPane ausgeben
    Von Baste im Forum Swing, Java2D/3D, SWT, JFace
    Antworten: 2
    Letzter Beitrag: 19.10.05, 08:01
  3. TabbedPane wird entweder zu groß oder zu klein angezeigt
    Von Aurelie im Forum Swing, Java2D/3D, SWT, JFace
    Antworten: 1
    Letzter Beitrag: 07.08.05, 14:14
  4. Splitpane - Divider fix?
    Von Skully im Forum Swing, Java2D/3D, SWT, JFace
    Antworten: 1
    Letzter Beitrag: 29.01.05, 22:54
  5. getSelection bei Radio Buttons, Anzeige rechts im SplitPane
    Von Katinki im Forum Swing, Java2D/3D, SWT, JFace
    Antworten: 3
    Letzter Beitrag: 04.01.05, 18:53