GUI에 큰 문제가 있습니다. 내 첫 번째 문제는 내가 JTextArea가 문자열을 표시하게하는 버튼을 누르면 텍스트 영역이 변경되어 모든 GUI와 모든 GUI를 푸시한다는 점입니다. 나는 많은 해결책을 시도했지만 아무것도 효과가 없었다.JScrollPane의 JTextArea가 표시되지 않습니다.
필자는 스크롤 영역에 텍스트 영역을 넣었습니다. 스크롤 패널에 텍스트가 표시되지 않기 때문에 잘 모릅니다. 누군가 내 코드를보고 내가 뭘 잘못하고 있는지 말해 줄 수 있습니까?
감사
왼쪽 하단에있는 작은 버튼을 누르면import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class myClass extends JFrame implements ActionListener{
public JButton picture = new JButton();
public JTextArea description = new JTextArea(10,30);
public JButton B1 = new JButton();
public JTextArea C1 = new JTextArea();
public myClass (String STP){
super(STP);
makeGUI();
}
public static void main(String[] args){
myClass test = new myClass("story");
}
public void actionPerformed(ActionEvent event){
Object source = event.getSource();
if (source==B1){
description.setText("hello world");
C1.setText("hello world");
}
}
public void makeGUI(){
JScrollPane scroll = new JScrollPane(description);
JPanel pane = new JPanel(new GridBagLayout());
Container con = this.getContentPane();
setBounds(50,50,600,600); //(x,-y,w,h) from north west
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// picture
GridBagConstraints gbc = new GridBagConstraints();
gbc.fill=GridBagConstraints.NONE;
gbc.ipadx=260;
gbc.ipady=310;
gbc.insets=new Insets(5,5,5,5);
gbc.gridx=0;
gbc.gridy=0;
gbc.gridwidth=2;
gbc.gridheight=3;
pane.add(picture,gbc);
// button 1
B1.addActionListener(this);
gbc.fill=GridBagConstraints.NONE;
gbc.ipadx=0;
gbc.ipady=10;
gbc.insets=new Insets(5,5,5,5);
gbc.gridx=0;
gbc.gridy=3;
gbc.gridwidth=1;
gbc.gridheight=1;
pane.add(B1,gbc);
//caption 1
gbc.fill=GridBagConstraints.HORIZONTAL;
gbc.ipadx=0;
gbc.ipady=30;
gbc.insets=new Insets(5,5,5,5);
gbc.gridx=1;
gbc.gridy=3;
gbc.gridwidth=3;
gbc.gridheight=1;
C1.setEditable(false);
C1.setLineWrap(true);
C1.setWrapStyleWord(true);
pane.add(C1,gbc);
// description !this is the part im having a problem with!
gbc.fill=GridBagConstraints.BOTH;
gbc.ipadx=100;
gbc.ipady=170;
gbc.insets=new Insets(10,10,10,0);
gbc.gridx=2;
gbc.gridy=0;
gbc.gridwidth=2;
gbc.gridheight=1;
description.setEditable(false);
description.setLineWrap(true);
description.setWrapStyleWord(true);
scroll.add(description);
pane.add(scroll,gbc);
con.add(pane);
setVisible(true);
}
}
시도. 두 텍스트 영역 모두에서 텍스트를 볼 수 있지만 하나만 작동합니다.
왜이 새로운 JScrollPane (설명)을 사용합니까? 그리고이 scroll.add (설명); –
+1은 'SSCCE'입니다. – Reimeus
[JScrollPane에있을 때 테이블이 보이지 않는 이유는 무엇입니까?] (http://stackoverflow.com/questions/22593867/why-is-my-table-not-visible-when-its-in-a) -jscrollpane) –