访问界面中的JTextArea组件显示信息,有时能显示信息,有时不能显示,不能显示的时候界面上的JTextArea组件都没有加载,不知道是什么原因,请教各们老鸟。
代码如下:
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new ISAG_SMS_GUI_Main().setVisible(true);
}
});


//new Thread(new ISAG_SMS_Master()).start();//启动线程

guiMain=ISAG_SMS_GUI_Main.getInstance();
guiMain.showMesage("display message!");
}  /**取得ISAG_SMS_GUI_Main的唯一实例 **/
  public static ISAG_SMS_GUI_Main getInstance(){
    if(guiMain == null){
     guiMain = new ISAG_SMS_GUI_Main();
    }
    
    return guiMain;
  } public static void showMesage(String strMessage){
  jTextArea1.append(strMessage+"\r\n");
  int length = jTextArea1.getText().length(); 
  jTextArea1.setCaretPosition(length);
  if ( length > 1000 ) {     
  jTextArea1.replaceRange("", 0, length - 1000); 
  } 
  
  }

解决方案 »

  1.   

    是不是 有背景图片?  你的背景图片防止的位置不对,把jTextArea1盖住了
      

  2.   

    没图片,jTextArea1放在JTabbedPane上面的。
      

  3.   

    代码如下,达人们帮忙调试看看咯。
    /*
     * ISAG_SMS_GUI_Main.java
     *
     * Created on __DATE__, __TIME__
     */package com.guiyangyaxun.isagsms.gui;/**
     *
     * @author  __USER__
     */
    public class ISAG_SMS_GUI_Main extends javax.swing.JFrame { public static ISAG_SMS_GUI_Main guiMain; /** Creates new form ISAG_SMS_GUI_Main */
    public ISAG_SMS_GUI_Main() {
    initComponents();
    } /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    //GEN-BEGIN:initComponents
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() { jToolBar1 = new javax.swing.JToolBar();
    jScrollPane2 = new javax.swing.JScrollPane();
    jTextArea1 = new javax.swing.JTextArea();
    menuBar = new javax.swing.JMenuBar();
    fileMenu = new javax.swing.JMenu();
    openMenuItem = new javax.swing.JMenuItem();
    saveMenuItem = new javax.swing.JMenuItem();
    saveAsMenuItem = new javax.swing.JMenuItem();
    exitMenuItem = new javax.swing.JMenuItem();
    editMenu = new javax.swing.JMenu();
    cutMenuItem = new javax.swing.JMenuItem();
    copyMenuItem = new javax.swing.JMenuItem();
    pasteMenuItem = new javax.swing.JMenuItem();
    deleteMenuItem = new javax.swing.JMenuItem();
    helpMenu = new javax.swing.JMenu();
    contentsMenuItem = new javax.swing.JMenuItem();
    aboutMenuItem = new javax.swing.JMenuItem(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); jToolBar1.setRollover(true); jTextArea1.setColumns(20);
    jTextArea1.setRows(5);
    jScrollPane2.setViewportView(jTextArea1); fileMenu.setText("File"); openMenuItem.setText("Open");
    fileMenu.add(openMenuItem); saveMenuItem.setText("Save");
    fileMenu.add(saveMenuItem); saveAsMenuItem.setText("Save As ...");
    fileMenu.add(saveAsMenuItem); exitMenuItem.setText("Exit");
    exitMenuItem.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    exitMenuItemActionPerformed(evt);
    }
    });
    fileMenu.add(exitMenuItem); menuBar.add(fileMenu); editMenu.setText("Edit"); cutMenuItem.setText("Cut");
    editMenu.add(cutMenuItem); copyMenuItem.setText("Copy");
    editMenu.add(copyMenuItem); pasteMenuItem.setText("Paste");
    editMenu.add(pasteMenuItem); deleteMenuItem.setText("Delete");
    editMenu.add(deleteMenuItem); menuBar.add(editMenu); helpMenu.setText("Help"); contentsMenuItem.setText("Contents");
    helpMenu.add(contentsMenuItem); aboutMenuItem.setText("About");
    helpMenu.add(aboutMenuItem); menuBar.add(helpMenu); setJMenuBar(menuBar); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
    getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(layout.createParallelGroup(
    javax.swing.GroupLayout.Alignment.LEADING).addComponent(
    jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 400,
    Short.MAX_VALUE).addGroup(
    layout.createSequentialGroup().addComponent(jScrollPane2,
    javax.swing.GroupLayout.PREFERRED_SIZE,
    javax.swing.GroupLayout.DEFAULT_SIZE,
    javax.swing.GroupLayout.PREFERRED_SIZE)
    .addContainerGap()));
    layout
    .setVerticalGroup(layout
    .createParallelGroup(
    javax.swing.GroupLayout.Alignment.LEADING)
    .addGroup(
    layout
    .createSequentialGroup()
    .addComponent(
    jToolBar1,
    javax.swing.GroupLayout.PREFERRED_SIZE,
    25,
    javax.swing.GroupLayout.PREFERRED_SIZE)
    .addPreferredGap(
    javax.swing.LayoutStyle.ComponentPlacement.RELATED)
    .addComponent(
    jScrollPane2,
    javax.swing.GroupLayout.PREFERRED_SIZE,
    javax.swing.GroupLayout.DEFAULT_SIZE,
    javax.swing.GroupLayout.PREFERRED_SIZE)
    .addContainerGap(142, Short.MAX_VALUE))); pack();
    }// </editor-fold>
    //GEN-END:initComponents private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitMenuItemActionPerformed
    System.exit(0);
    }//GEN-LAST:event_exitMenuItemActionPerformed /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {
    public void run() {
    new ISAG_SMS_GUI_Main().setVisible(true);
    }
    }); guiMain=ISAG_SMS_GUI_Main.getInstance();
    guiMain.jTextArea1.setText("FDFDD");
            
    } /**取得CMPPMTSocketProcess的唯一实例 **/
    public static ISAG_SMS_GUI_Main getInstance() {
    if (guiMain == null) {
    guiMain = new ISAG_SMS_GUI_Main();
    } return guiMain;
    } //GEN-BEGIN:variables
    // Variables declaration - do not modify
    private javax.swing.JMenuItem aboutMenuItem;
    private javax.swing.JMenuItem contentsMenuItem;
    private javax.swing.JMenuItem copyMenuItem;
    private javax.swing.JMenuItem cutMenuItem;
    private javax.swing.JMenuItem deleteMenuItem;
    private javax.swing.JMenu editMenu;
    private javax.swing.JMenuItem exitMenuItem;
    private javax.swing.JMenu fileMenu;
    private javax.swing.JMenu helpMenu;
    private javax.swing.JScrollPane jScrollPane2;
    private static javax.swing.JTextArea jTextArea1;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JMenuItem openMenuItem;
    private javax.swing.JMenuItem pasteMenuItem;
    private javax.swing.JMenuItem saveAsMenuItem;
    private javax.swing.JMenuItem saveMenuItem;
    // End of variables declaration//GEN-END:variables}