当前位置: 技术问答>java相关
TEXTAREA显示问题
来源: 互联网 发布时间:2015-10-14
本文导语: class inputJPanel extends JPanel { public inputJPanel() { textArea = new JTextArea(25,70); scrollPane = new JScrollPane(textArea); ...
class inputJPanel extends JPanel
{
public inputJPanel()
{
textArea = new JTextArea(25,70);
scrollPane = new JScrollPane(textArea);
scrollPane.setSize(800,600);
add(scrollPane);
repaint();
}
public JTextArea textArea;
public JScrollPane scrollPane;
}
public void actionPerformed(ActionEvent evt)
{
if(evt.getSource() instanceof JMenuItem)
{
String arg = evt.getActionCommand();
if(arg.equals("新建"))
{
System.out.print(50);
getContentPane().removeAll();
GridBagConstraints gbc = new GridBagConstraints();
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.anchor = GridBagConstraints.NORTH;
gbc.weightx = 100;
gbc.weighty = 0;
p = new inputJPanel();
//getContentPane().setLayout();
getContentPane().add(p);
}
}
}
TEXTAREA在内部类里面,如果我不加在触发里面,他是显示的,但是一旦加在触发里面,他一定要触发以后,最大化窗口,他就会显示,再最小化他也在那里,同样在最大化窗口的状况下,触发,他也不显示,在最小化后他就显示了.
{
public inputJPanel()
{
textArea = new JTextArea(25,70);
scrollPane = new JScrollPane(textArea);
scrollPane.setSize(800,600);
add(scrollPane);
repaint();
}
public JTextArea textArea;
public JScrollPane scrollPane;
}
public void actionPerformed(ActionEvent evt)
{
if(evt.getSource() instanceof JMenuItem)
{
String arg = evt.getActionCommand();
if(arg.equals("新建"))
{
System.out.print(50);
getContentPane().removeAll();
GridBagConstraints gbc = new GridBagConstraints();
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.anchor = GridBagConstraints.NORTH;
gbc.weightx = 100;
gbc.weighty = 0;
p = new inputJPanel();
//getContentPane().setLayout();
getContentPane().add(p);
}
}
}
TEXTAREA在内部类里面,如果我不加在触发里面,他是显示的,但是一旦加在触发里面,他一定要触发以后,最大化窗口,他就会显示,再最小化他也在那里,同样在最大化窗口的状况下,触发,他也不显示,在最小化后他就显示了.
|
删除或是添加控件后,需要重画一下
validate()或是updateUI()
validate()或是updateUI()