在没有 Gui 编辑器的情况下向 Gui 添加 3 个 jTextArea
Adding 3 jTextArea to Gui without the Gui editor
我接了一个学生的作业,我的任务是为它写一个自动单词编译,快完成了,我遇到了一个问题。我必须向 gui 添加 3 或 4 jTextAreas
。问题是他怎么写的代码我只能加一个jTextArea
.
这是 1 的样子 Jtextarea
:
这就是我希望它拥有它的方式:
这是管理键盘孔布局的代码:
button = new CustomJButton[button_size];
jPanel1 = new javax.swing.JPanel();
jPanel2 = new javax.swing.JPanel();
jTextArea = new javax.swing.JTextArea();
// BorderLayout
bl = new java.awt.BorderLayout();
this.setLayout(bl);
this.add(jTextArea, BorderLayout.NORTH);
Font font1 = new Font("SansSerif", Font.BOLD, 20);
jTextArea.setFont(font1);
jTextArea.setFocusable(false);
menuButtongbc = new GridBagConstraints();
// vergrößert die Buttons in BEIDE Richtungen // HORIZONTAL / VERTICAL
menuButtongbc.fill = GridBagConstraints.BOTH;
menuButtongbc.insets = new Insets(1,1,1,1);
menuButtongbc.weightx = 1;
menuButtongbc.weighty = 1;
letterButtongbc = new GridBagConstraints();
// vergrößert die Buttons in BEIDE Richtungen // HORIZONTAL / VERTICAL
letterButtongbc.fill = GridBagConstraints.BOTH;
letterButtongbc.insets = new Insets(1,1,1,1);
letterButtongbc.weightx = 1;
letterButtongbc.weighty = 1;
jPanel1.setLayout(new java.awt.GridBagLayout()); // Layout left side
jPanel2.setLayout(new java.awt.GridBagLayout()); // Layout right side
//******************************************************************************
// Button left Block / Buttonborder / Resize ButtonImage
//******************************************************************************
int xVar = 0; // Hilfvariable für X und Y Zuordnung
int yVar = 0; // Hilfvariable für X und Y Zuordnung
for ( int menuButtonArray = 0 ; menuButtonArray < 4 ; menuButtonArray++ ){
CustomJButton a = new CustomJButton(); // a : Hilfsvariable
button[menuButtonArray] = a;
button[menuButtonArray].setFont(new Font("Arial", Font.PLAIN, 40));
button[menuButtonArray].setBackground(backgroundColor);
button[menuButtonArray].setOpaque(true); // Test für MAC
button[menuButtonArray].setMinimumSize(new java.awt.Dimension(75, 75));
button[menuButtonArray].setPreferredSize(new java.awt.Dimension(100, 100));
button[menuButtonArray].setFocusable(false);
button[menuButtonArray].setBorder(BorderFactory.createLineBorder(Color.black, 4));
menuButtongbc.gridx = xVar; // X und Y Zuweisung der Button im GridbagLayout
menuButtongbc.gridy = yVar; // X und Y Zuweisung der Button im GridbagLayout
xVar++;
if(xVar == 2){ yVar++ ; xVar = 0; }
jPanel1.add( button[menuButtonArray] , menuButtongbc );
}
add(jPanel1, java.awt.BorderLayout.LINE_START); //getContentPane().
//******************************************************************************
// Array // Right side
//******************************************************************************
xVar = 0;
yVar = 0;
// ausgabe.length
for ( int letterButtonArray = 4 ; letterButtonArray < 34 ; letterButtonArray++ ){
CustomJButton a = new CustomJButton(); // a : Hilfsvariable
button[letterButtonArray] = a;
button[letterButtonArray].setFont(new Font("Arial", Font.PLAIN, Integer.parseInt(read[9])));
button[letterButtonArray].setBackground(backgroundColor);
button[letterButtonArray].setOpaque(true); // Test für MAC
button[letterButtonArray].setMinimumSize(new java.awt.Dimension(20, 20));
button[letterButtonArray].setPreferredSize(new java.awt.Dimension(100, 100));
button[letterButtonArray].setBorder(new javax.swing.border.
SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
button[letterButtonArray].setFocusable(false);
// X und Y Zuweisung der Button im GridbagLayout
letterButtongbc.gridx = xVar;
letterButtongbc.gridy = yVar;
xVar++;
if(xVar > 14){ yVar++ ; xVar = 0; } // 17 / für Buttons in einem jPanel
jPanel2.add( button[letterButtonArray] , letterButtongbc ); // jPanel2
}
add(jPanel2 , java.awt.BorderLayout.CENTER ); // getContentPane().
pack();
// Berechnung der Position über der Taskleiste
Dimension frameSize = this.getSize();
// BildschirmBreite - FensterBreite / 2
setLocation( (int)( screenSizeWidth - frameSize.width ) / 2 ,
// BildschirmHöhe - FensterHöhe - TaskbarHöhe
screenSizeHeight - frameSize.height - taskbarSize );
创建一个水平框并在水平框中输入 3 个文本区域。
Box hBox= Box.createHorizontalBox();
hBox.add(TextArea1);
hBox.add(TextArea2);
hBox.add(TextArea3);
我接了一个学生的作业,我的任务是为它写一个自动单词编译,快完成了,我遇到了一个问题。我必须向 gui 添加 3 或 4 jTextAreas
。问题是他怎么写的代码我只能加一个jTextArea
.
这是 1 的样子 Jtextarea
:
这就是我希望它拥有它的方式:
这是管理键盘孔布局的代码:
button = new CustomJButton[button_size];
jPanel1 = new javax.swing.JPanel();
jPanel2 = new javax.swing.JPanel();
jTextArea = new javax.swing.JTextArea();
// BorderLayout
bl = new java.awt.BorderLayout();
this.setLayout(bl);
this.add(jTextArea, BorderLayout.NORTH);
Font font1 = new Font("SansSerif", Font.BOLD, 20);
jTextArea.setFont(font1);
jTextArea.setFocusable(false);
menuButtongbc = new GridBagConstraints();
// vergrößert die Buttons in BEIDE Richtungen // HORIZONTAL / VERTICAL
menuButtongbc.fill = GridBagConstraints.BOTH;
menuButtongbc.insets = new Insets(1,1,1,1);
menuButtongbc.weightx = 1;
menuButtongbc.weighty = 1;
letterButtongbc = new GridBagConstraints();
// vergrößert die Buttons in BEIDE Richtungen // HORIZONTAL / VERTICAL
letterButtongbc.fill = GridBagConstraints.BOTH;
letterButtongbc.insets = new Insets(1,1,1,1);
letterButtongbc.weightx = 1;
letterButtongbc.weighty = 1;
jPanel1.setLayout(new java.awt.GridBagLayout()); // Layout left side
jPanel2.setLayout(new java.awt.GridBagLayout()); // Layout right side
//******************************************************************************
// Button left Block / Buttonborder / Resize ButtonImage
//******************************************************************************
int xVar = 0; // Hilfvariable für X und Y Zuordnung
int yVar = 0; // Hilfvariable für X und Y Zuordnung
for ( int menuButtonArray = 0 ; menuButtonArray < 4 ; menuButtonArray++ ){
CustomJButton a = new CustomJButton(); // a : Hilfsvariable
button[menuButtonArray] = a;
button[menuButtonArray].setFont(new Font("Arial", Font.PLAIN, 40));
button[menuButtonArray].setBackground(backgroundColor);
button[menuButtonArray].setOpaque(true); // Test für MAC
button[menuButtonArray].setMinimumSize(new java.awt.Dimension(75, 75));
button[menuButtonArray].setPreferredSize(new java.awt.Dimension(100, 100));
button[menuButtonArray].setFocusable(false);
button[menuButtonArray].setBorder(BorderFactory.createLineBorder(Color.black, 4));
menuButtongbc.gridx = xVar; // X und Y Zuweisung der Button im GridbagLayout
menuButtongbc.gridy = yVar; // X und Y Zuweisung der Button im GridbagLayout
xVar++;
if(xVar == 2){ yVar++ ; xVar = 0; }
jPanel1.add( button[menuButtonArray] , menuButtongbc );
}
add(jPanel1, java.awt.BorderLayout.LINE_START); //getContentPane().
//******************************************************************************
// Array // Right side
//******************************************************************************
xVar = 0;
yVar = 0;
// ausgabe.length
for ( int letterButtonArray = 4 ; letterButtonArray < 34 ; letterButtonArray++ ){
CustomJButton a = new CustomJButton(); // a : Hilfsvariable
button[letterButtonArray] = a;
button[letterButtonArray].setFont(new Font("Arial", Font.PLAIN, Integer.parseInt(read[9])));
button[letterButtonArray].setBackground(backgroundColor);
button[letterButtonArray].setOpaque(true); // Test für MAC
button[letterButtonArray].setMinimumSize(new java.awt.Dimension(20, 20));
button[letterButtonArray].setPreferredSize(new java.awt.Dimension(100, 100));
button[letterButtonArray].setBorder(new javax.swing.border.
SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
button[letterButtonArray].setFocusable(false);
// X und Y Zuweisung der Button im GridbagLayout
letterButtongbc.gridx = xVar;
letterButtongbc.gridy = yVar;
xVar++;
if(xVar > 14){ yVar++ ; xVar = 0; } // 17 / für Buttons in einem jPanel
jPanel2.add( button[letterButtonArray] , letterButtongbc ); // jPanel2
}
add(jPanel2 , java.awt.BorderLayout.CENTER ); // getContentPane().
pack();
// Berechnung der Position über der Taskleiste
Dimension frameSize = this.getSize();
// BildschirmBreite - FensterBreite / 2
setLocation( (int)( screenSizeWidth - frameSize.width ) / 2 ,
// BildschirmHöhe - FensterHöhe - TaskbarHöhe
screenSizeHeight - frameSize.height - taskbarSize );
创建一个水平框并在水平框中输入 3 个文本区域。
Box hBox= Box.createHorizontalBox();
hBox.add(TextArea1);
hBox.add(TextArea2);
hBox.add(TextArea3);