Nao consigo fazer o scroll funcionar! Alguma dica?
[code]package gui;
import javax.swing.;
import javax.swing.border.EtchedBorder;
import java.awt.;
import java.awt.event.KeyEvent;
public class principalFrame extends JFrame {
private JMenuBar BarraMenu = null;
private JMenu mnuArquivo = null;
private JMenuItem mnuSair = null;
// private JTextField tf_usuario = null;
private static final long serialVersionUID = 1L;
private JPanel jContentPane = null;
private JTextField jTextFieldChat = null;
private JButton jButtonChat = null;
// private JPanel chat;
private FreeHand jPanelFree = new FreeHand(); // @jve:decl-index=0:visual-constraint="119,620"
private static principalFrame executa;
private JButton jButtonEnviarDraw = null;
// private JLabel jLabel = null;
private JTextArea areaChat = null;
private Color white = new Color(255,255,255); // @jve:decl-index=0:
private JComboBox jComboBoxUsuarios = null;
/*private ArrayList messages = new ArrayList();*/ // @jve:decl-index=0:
//garante apenas uma unica instancia na memoria
static{
executa = new principalFrame();
}
/** Construtor Default **/
public principalFrame() {
super();
setVisible(false);
}
private void initialize() {
//finaliza a janela de login
loginFrame.getInstance().finish();
jPanelFree.setSize(new Dimension(367, 498));
jPanelFree.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED));
jPanelFree.setLocation(new Point(418, 10));
this.setSize(800, 600);
this.setContentPane(getJContentPane());
this.setJMenuBar(getBarraMenu());
this.setTitle("DrawChat - Ferramenta de Ensino a Distancia");
executa.setVisible(true);
executa.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
executa.setLocation(100,100);
add(scroll, BorderLayout.CENTER);
}
private JMenuBar getBarraMenu() {
if (BarraMenu == null){
BarraMenu = new JMenuBar();
BarraMenu.add(getMnuArquivo());
}
return BarraMenu;
}
private JMenu getMnuArquivo() {
if (mnuArquivo == null){
mnuArquivo = new JMenu();
mnuArquivo.setText("Arquivo");
mnuArquivo.add(getMnuSair());
}
return mnuArquivo;
}
private JMenuItem getMnuSair() {
if (mnuSair == null){
mnuSair = new JMenuItem();
mnuSair.setText("Sair");
mnuSair.setMnemonic(KeyEvent.VK_S);
mnuSair.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
System.exit(0);
}
});
}
return mnuSair;
}
public static principalFrame getInstance()
{
return executa;
}
public void openPrincipal()
{
initialize();
}
private JPanel getJContentPane() {
if (jContentPane == null) {
//jLabel = new JLabel();
//jLabel.setBounds(new java.awt.Rectangle(0,-2,792,542));
//jLabel.setFont(new Font("Dialog", Font.BOLD, 36));
//jLabel.setIcon(new ImageIcon(getClass().getResource("/gui/background.jpg")));
//jLabel.setText("Background");
jContentPane = new JPanel();
jContentPane.setLayout(null);
jContentPane.add(getJTextFieldChat(), null);
jContentPane.add(getJButtonChat(), null);
jContentPane.add(getJPanel_Free(), null);
jContentPane.add(getJButtonEnviarDraw(), null);
jContentPane.add(getJTextAreaChat(), null);
//jContentPane.add(jLabel, null);
jContentPane.add(getJComboBoxUsuarios(), null);
jContentPane.add(scroll, BorderLayout.CENTER);
}
return jContentPane;
}
/**
* This method initializes jTextFieldChat
*
* @return javax.swing.JTextField
*/
private JTextField getJTextFieldChat() {
if (jTextFieldChat == null) {
jTextFieldChat = new JTextField();
jTextFieldChat.setBounds(new Rectangle(17, 510, 340, 23));
}
return jTextFieldChat;
}
private JButton getJButtonChat() {
if (jButtonChat == null) {
jButtonChat = new JButton();
jButtonChat.setBounds(new Rectangle(358, 510, 52, 23));
jButtonChat.setText("Ok");
jButtonChat.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
enviaMensagem();
}
});
}
return jButtonChat;
}
private void enviaMensagem(){
String mensagem = this.jTextFieldChat.getText();
if(mensagem.equals("")){}
else{
//addMessage(mensagem);
String nick = loginFrame.user.getNick();
String texto = nick+": "+mensagem;
if(areaChat.getText().equals("")){
areaChat.setText(texto);
jTextFieldChat.setText("");
}else{
areaChat.setText(areaChat.getText()+"\n"+texto);
jTextFieldChat.setText("");
}
}
}
private FreeHand getJPanel_Free(){
if(jPanelFree == null){
jPanelFree.setBounds(new Rectangle(0,0,100,100));
}
return jPanelFree;
}
/**
* This method initializes jButtonEnviarDraw
*
* @return javax.swing.JButton
*/
private JButton getJButtonEnviarDraw() {
if (jButtonEnviarDraw == null) {
jButtonEnviarDraw = new JButton();
jButtonEnviarDraw.setBounds(new Rectangle(715, 510, 70, 23));
jButtonEnviarDraw.setText("Enviar");
}
return jButtonEnviarDraw;
}
JScrollPane scroll = new JScrollPane(areaChat);
private JTextArea getJTextAreaChat() {
if (areaChat == null) {
add(scroll, BorderLayout.CENTER);
areaChat = new JTextArea();
areaChat.setLineWrap(true);
areaChat.setAutoscrolls(true);
areaChat.setLayout(null);
areaChat.setEditable(false);
areaChat.setBounds(new Rectangle(19, 38, 391, 470));
areaChat.setBackground(this.white);
setLocationRelativeTo(null);
setVisible(true);
}
return areaChat;
}
/**
* This method initializes jComboBoxUsuarios
*
* @return javax.swing.JComboBox
*/
private JComboBox getJComboBoxUsuarios() {
if (jComboBoxUsuarios == null) {
jComboBoxUsuarios = new JComboBox();
jComboBoxUsuarios.setBounds(new Rectangle(18, 10, 393, 25));
jComboBoxUsuarios.setMaximumRowCount(10);
jComboBoxUsuarios.addItem("");
listaUsuarios();
jComboBoxUsuarios.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
selecionaUsuarios();
}
});
}
return jComboBoxUsuarios;
}
private void selecionaUsuarios()
{
if(this.jComboBoxUsuarios.getSelectedItem().equals(loginFrame.user.getNick()))
{
String usuario = loginFrame.user.getNick();
JOptionPane.showMessageDialog(this,"Usuário selecionado: "+usuario, "",JOptionPane.INFORMATION_MESSAGE);
/*Usuario usuarios = (Usuario)this.jComboBoxUsuarios.getSelectedItem();
tf_usuario.setText(usuarios.getNick());
jComboBoxUsuarios.setSelectedItem(String.valueOf(usuarios.getNick()));
tf_usuario.setEnabled(false);*/
}
}
private void listaUsuarios(){
String user = loginFrame.user.getNick();
this.jComboBoxUsuarios.addItem(user);
}
/*public void addMessage(String msg) {
messages.add(msg);
synchronized (messages) {
// sinaliza para quem está esperando
messages.notifyAll();
}
}*/
}[/code]