Größe von jPanel bzw. jTextArea (in jScrollpane) anpassen

Status
Nicht offen für weitere Antworten.

snoop83

Mitglied
wie bereits in einem anderen Posting erwähnt, arbeite ich mich zur Zeit in Java ein und soll dort als erstes eine GUI implementieren. Ich arbeite hier mit einer Verschachtelung von Gridlayout und Borderlayout.

Das ganze sieht so aus:
gui_borland_screen.gif


skizze_gui_2.gif


erstellt mit Borland JBuilder 2005..

Leider schaffe ich es nicht, die Größe meiner jScrollPane (dort eingebettet ist eine jTextArea) anzupassen. Die ist viel zu groß, wie man sieht ..

Die ScrollPane liegt in einem Borderlayout .. dort wiederrum liegt oben [Spielfeld (links, z.Z. noch Platzhalter) + Panel mit 7 Info-Labels] und unten [Panel mit: Chat-Ausgabe (Textarea), Chateingabezeile sowie Senden-Button]

Was muss ich tun, damit ich die Textarea in der Scrollpane verkleinern kann (ca. halbe Höhe)

hier mein code:
Code:
import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JTextArea;
import java.awt.*;
import java.awt.event.*;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JSplitPane;
import javax.swing.JCheckBox;
import javax.swing.JRadioButton;
import javax.swing.JToggleButton;
import javax.swing.JEditorPane;
import javax.swing.JLabel;
import com.borland.jbcl.layout.PaneLayout;
import com.borland.jbcl.layout.*;
import javax.swing.JTextField;
import javax.swing.JList;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JScrollPane;

public class Frame1 extends JFrame {
    BorderLayout borderLayoutGesamt = new BorderLayout();
    JPanel jPanelSpielInfoFeldChat = new JPanel();
    JLabel jLabelInfozeile = new JLabel();
    GridLayout gridLayoutSpielInfoFeldChat = new GridLayout();
    JPanel jPanelSpielfeldInfofeld = new JPanel();
    JPanel jPanelChatGesamt = new JPanel();
    BorderLayout borderLayoutSpielfeldInfofeld = new BorderLayout();
    BorderLayout borderLayoutChatGesamt = new BorderLayout();
    JPanel jPanelChatEingabe = new JPanel();
    BorderLayout borderLayout4 = new BorderLayout();
    BorderLayout borderLayout5 = new BorderLayout();
    JPanel jPanelInfofeld = new JPanel();
    GridLayout gridLayout2 = new GridLayout();
    JLabel jLabelNameSpieler = new JLabel();
    JLabel jLabelNameGegner = new JLabel();
    GridLayout gridLayoutInfofeld = new GridLayout();
    JLabel jLabelIPSpieler = new JLabel();
    JLabel jLabelIPGegner = new JLabel();
    JLabel jLabelSpielphase = new JLabel();
    JLabel jLabelSpieldauer = new JLabel();
    JLabel jLabelPunktestand = new JLabel();
    JEditorPane jEditorPaneSpielfeld = new JEditorPane();
    JTextField jTextFieldChatEingabe = new JTextField();
    JButton jButtonChatSenden = new JButton();
    BorderLayout borderLayoutChatEingabe = new BorderLayout();
    JMenuBar hauptmenu = new JMenuBar();
    JMenu jmenuspiel = new JMenu("Spiel");
    JMenu jmenuhilfe = new JMenu("Hilfe");
    JMenuItem jmenuspielneu = new JMenuItem("neues Spiel", 'n');
    JMenuItem jmenuspielnameaendern = new JMenuItem("Spielername ändern", 'S');
    JMenuItem jmenuspielhighscore = new JMenuItem("Highscore", 'H');
    JMenuItem jmenuspielbeenden = new JMenuItem("Spiel beenden", 'b');
    JMenuItem jmenuhilfehandbuch = new JMenuItem("Handbuch", 'H');
    JMenuItem jmenuhilfetutorial = new JMenuItem("Tutorial", 'T');
    JScrollPane jScrollPaneChatAusgabe = new JScrollPane();
    JTextArea jTextAreaChatAusgabe = new JTextArea();


    public Frame1() {
        try {
            jbInit();
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }

    private void jbInit() throws Exception {
        getContentPane().setLayout(borderLayoutGesamt);
        jPanelSpielInfoFeldChat.setBackground(SystemColor.control);
        jPanelSpielInfoFeldChat.setLayout(gridLayoutSpielInfoFeldChat);
        jPanelInfofeld.setBackground(SystemColor.control);
        jPanelInfofeld.setLayout(gridLayoutInfofeld);
        gridLayoutInfofeld.setColumns(1);
        gridLayoutInfofeld.setRows(7);
        jLabelInfozeile.setText("Informationszeile");
        jLabelNameSpieler.setText(" Spielername (Farbe)");
        jLabelNameGegner.setText(" Gegnername (Farbe)");
        jLabelIPSpieler.setText(" IP (lokal): xxx.xxx.xxx.xxx");
        jLabelIPGegner.setText(" IP (Gegner): xxx.xxx.xxx.xxx");
        jLabelSpielphase.setText(" Spielphase: 1, 2 oder 3");
        jLabelSpieldauer.setText(" Spieldauer: xx:xx");
        jLabelPunktestand.setText(" Punktestand: x : x");
        jEditorPaneSpielfeld.setBackground(Color.lightGray);
        jEditorPaneSpielfeld.setText("Spielfeld-Platzhalter !!");
        jTextFieldChatEingabe.setText("Chat-Eingabefeld");
        jButtonChatSenden.setText("Senden");
        jPanelChatEingabe.setLayout(borderLayoutChatEingabe);
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
        this.setJMenuBar(hauptmenu);
        this.setResizable(false);
        this.setTitle("Mühle");
        this.setSize(700, 550);
        this.setLocation(50, 50);
        jmenuspiel.setToolTipText("");
        jmenuspiel.setText("Spiel");
        jmenuhilfe.setText("Hilfe");
        jmenuspielneu.setText("neues Spiel");
        jmenuspielnameaendern.setText("Spielername ändern");
        jmenuspielhighscore.setText("Highscore");
        jmenuspielbeenden.setText("Spiel beenden");
        jmenuhilfehandbuch.setText("Handbuch");
        jmenuhilfetutorial.setText("Tutorial");
        jTextAreaChatAusgabe.setText(
                "TextArea (Chat-Ausgabe) .. Zeilenumbruch: nein  ;  in Scrollpane: " +
                "ja");
        jTextAreaChatAusgabe.setWrapStyleWord(true);
        jScrollPaneChatAusgabe.setHorizontalScrollBarPolicy(JScrollPane.
                HORIZONTAL_SCROLLBAR_NEVER);
        jScrollPaneChatAusgabe.setVerticalScrollBarPolicy(JScrollPane.
                VERTICAL_SCROLLBAR_ALWAYS);
        jScrollPaneChatAusgabe.setMinimumSize(new Dimension(10, 10));
        this.getContentPane().add(jLabelInfozeile, java.awt.BorderLayout.SOUTH);
        gridLayoutSpielInfoFeldChat.setRows(2);
        this.getContentPane().add(jPanelSpielInfoFeldChat,
                                  java.awt.BorderLayout.CENTER);
        jPanelSpielfeldInfofeld.setBackground(SystemColor.control);
        jPanelSpielfeldInfofeld.setLayout(borderLayoutSpielfeldInfofeld);
        jPanelChatGesamt.setBackground(SystemColor.control);
        jPanelChatGesamt.setLayout(borderLayoutChatGesamt);
        jPanelChatEingabe.setBackground(SystemColor.control);
        jPanelSpielInfoFeldChat.add(jPanelSpielfeldInfofeld);
        jPanelSpielfeldInfofeld.add(jPanelInfofeld, java.awt.BorderLayout.EAST);
        // Label-text einrichten
        jPanelInfofeld.add(jLabelNameSpieler);
        jPanelInfofeld.add(jLabelNameGegner);
        jPanelInfofeld.add(jLabelIPSpieler);
        jPanelInfofeld.add(jLabelIPGegner);
        jPanelInfofeld.add(jLabelSpielphase);
        jPanelInfofeld.add(jLabelSpieldauer);
        jPanelInfofeld.add(jLabelPunktestand);
        jPanelSpielfeldInfofeld.add(jEditorPaneSpielfeld,
                                    java.awt.BorderLayout.CENTER);
        jPanelSpielInfoFeldChat.add(jPanelChatGesamt);
        jPanelChatGesamt.add(jPanelChatEingabe, java.awt.BorderLayout.SOUTH);
        jPanelChatEingabe.add(jButtonChatSenden, java.awt.BorderLayout.EAST);
        jPanelChatEingabe.add(jTextFieldChatEingabe,
                              java.awt.BorderLayout.CENTER);

        // Menü erstellen
        hauptmenu.add(jmenuspiel);
        hauptmenu.add(jmenuhilfe);
        jmenuspiel.add(jmenuspielneu);
        jmenuspiel.addSeparator();
        jmenuspiel.add(jmenuspielnameaendern);
        jmenuspiel.add(jmenuspielhighscore);
        jmenuspiel.addSeparator();
        jmenuspiel.add(jmenuspielbeenden);
        jmenuhilfe.add(jmenuhilfehandbuch);
        jmenuhilfe.add(jmenuhilfetutorial);
        jPanelChatGesamt.add(jScrollPaneChatAusgabe,
                             java.awt.BorderLayout.CENTER);
        jScrollPaneChatAusgabe.getViewport().add(jTextAreaChatAusgabe);

        // Actionlistener einrichten
        jmenuhilfetutorial.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent event){
            jLabelInfozeile.setText("Action: Click: Menü: Tutorial");
            }
          }
        );

        jmenuhilfehandbuch.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent event){
            jLabelInfozeile.setText("Action: Click: Menü: Handbuch");
            }
          }
        );

        jButtonChatSenden.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent event){
            jLabelInfozeile.setText("Action: Click: Chat: Button Senden");
            }
          }
        );

        jmenuspielbeenden.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent event){
            jLabelInfozeile.setText("Action: Click: Menü: Spiel beenden");
            }
          }
        );

        jmenuspielhighscore.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent event){
            jLabelInfozeile.setText("Action: Click: Menü: Highscore");
            }
          }
        );

        jmenuspielnameaendern.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent event){
            jLabelInfozeile.setText("Action: Click: Menü: Namen ändern");
            }
          }
        );

        jmenuspielneu.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent event){
            jLabelInfozeile.setText("Action: Click: Menü: neues Spiel");
            }
          }
        );


        // Frame anzeigen
        this.setVisible(true);
    }


    public static void main(String[] args){
       Frame1 hauptfenster = new Frame1();
       }


}
 
snoop83 hat gesagt.:
Was muss ich tun, damit ich die Textarea in der Scrollpane verkleinern kann (ca. halbe Höhe)

Verwende ein GridBagLayout für die gesamte GUI. BorderLayout hat eben für CENTER die Eigenschaft, dass die darin befindliche Komponente ausgedehnt wird.
 
Status
Nicht offen für weitere Antworten.

Zurück
Oben