Hey Leute!
Ich habe hier 3 JTextAreas in einem GridBagLayout, jedoch sprengt die Größe der JTextAreas, die "LineWrap" auf "true" haben den Rahmen des GUI.
Ich weiß nicht woran das liegen könnte! Sobald ich ein Zeichen hineinschreibe sieht jedoch wieder alles normal aus.
Das GUI sollte aber von Beginn an normal aussehen.
Hier der Code (In diesem Code ist nur die onYomiArea mit "LineWrap" auf "true", das ist die erste von links im GUI):
Ich habe hier 3 JTextAreas in einem GridBagLayout, jedoch sprengt die Größe der JTextAreas, die "LineWrap" auf "true" haben den Rahmen des GUI.
Ich weiß nicht woran das liegen könnte! Sobald ich ein Zeichen hineinschreibe sieht jedoch wieder alles normal aus.
Das GUI sollte aber von Beginn an normal aussehen.
Hier der Code (In diesem Code ist nur die onYomiArea mit "LineWrap" auf "true", das ist die erste von links im GUI):
Java:
import java.awt.*;
import javax.swing.*;
import java.util.*;
public class KaBooGUI {
private JFrame frame = new JFrame("KaBooGUI");
private JTextField kanjiField = new JTextField("人");
private DrawPanel drawPanel = new DrawPanel();
private JLabel onYomiLabel = new JLabel("Onyomi:");
private JTextArea onYomiArea = new JTextArea(5,8);
private JLabel kunYomiLabel = new JLabel("Kunyomi:");
private JTextArea kunYomiArea = new JTextArea(5,8);
private JLabel meaningLabel = new JLabel("Bedeutung:");
private JTextArea meaningArea = new JTextArea(5,8);
private JButton actionButton = new JButton("GO!");
private ArrayList<JLabel> compList1 = new ArrayList<JLabel>();
private ArrayList<JTextArea> compList2 = new ArrayList<JTextArea>();
public void fillArrayLists() {
compList1.add(onYomiLabel);
compList1.add(kunYomiLabel);
compList1.add(meaningLabel);
compList2.add(onYomiArea);
compList2.add(kunYomiArea);
compList2.add(meaningArea);
}
public void configureComponents() {
kanjiField.setFont(kanjiField.getFont().deriveFont((float)140));
kanjiField.setEditable(false);
onYomiArea.setLineWrap(true);
/*
for(int i=0;i<(compList2.size());i++) {
compList2.get(i).setLineWrap(true);
}
*/
}
public void addComponentsToPane(Container pane) {
pane.setLayout(new GridBagLayout());
int topInset = 10;
int leftInset = 10;
int bottomInset = 10;
int rightInset = 10;
// kanjiField
GridBagConstraints kanjiFieldConstraints = new GridBagConstraints();
kanjiFieldConstraints.fill = GridBagConstraints.HORIZONTAL;
kanjiFieldConstraints.gridx = 0;
kanjiFieldConstraints.gridy = 0;
kanjiFieldConstraints.gridheight = 2;
kanjiFieldConstraints.insets = new Insets(topInset,leftInset,10,10);
pane.add(kanjiField, kanjiFieldConstraints);
// drawPanel
GridBagConstraints drawPanelConstraints = new GridBagConstraints();
drawPanelConstraints.fill = GridBagConstraints.HORIZONTAL;
drawPanelConstraints.gridx = 0;
drawPanelConstraints.gridy = 2;
drawPanelConstraints.gridheight = 2;
drawPanelConstraints.ipady = 20;
drawPanelConstraints.insets = new Insets(0,leftInset+20,bottomInset,leftInset+20);
pane.add(drawPanel, drawPanelConstraints);
// onYomi, kunYomi, meaning
for(int i=0;i<(compList1.size());i++) {
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.HORIZONTAL;
c.gridx = i+1;
c.gridy = 0;
c.insets = new Insets(topInset,30,0,30);
pane.add(compList1.get(i), c);
}
for(int i=0;i<(compList2.size());i++) {
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.HORIZONTAL;
c.gridx = i+1;
c.gridy = 1;
c.ipady = 40;
c.insets = new Insets(0,10,0,10);
pane.add(compList2.get(i), c);
}
// actionButton
GridBagConstraints actionButtonConstraints = new GridBagConstraints();
actionButtonConstraints.fill = GridBagConstraints.HORIZONTAL;
actionButtonConstraints.gridx = 2;
actionButtonConstraints.gridy = 2;
actionButtonConstraints.insets = new Insets(10,30,bottomInset,30);
pane.add(actionButton, actionButtonConstraints);
}
public void createAndShowGUI() {
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fillArrayLists();
configureComponents();
addComponentsToPane(frame.getContentPane());
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
new KaBooGUI().createAndShowGUI();
}
}
class DrawPanel extends JPanel {
private static final long serialVersionUID = 1L;
public void paintComponent(Graphics g) {
g.fillRect(0, 0, getWidth(), getHeight());
}
}