JtextArea not updating
Hi I have a strange problem with appending text to a JTextArea.
Basically I have a JinternalFrame with a table. When the user clicks on a particular row, I want that some of the data in that row to be displayed in a dialog which has a JTextArea included.
here is part of the code of from the JinternalFrame that calls the Dialog
private JTable getStatTable(){
if (cTable ==null){
cTable =new JTable(){
privatestaticfinallong serialVersionUID = 1;
public TableCellEditor getCellEditor(int row,int column)
{
if (column == 1 && !caseTableEditors.isEmpty())
{
return (TableCellEditor)caseTableEditors.get(row);
}else{
return super.getCellEditor(row, column);
}
}
};
cTable.setSize(new java.awt.Dimension(650,140));
cTable.setMinimumSize(new java.awt.Dimension(650,140));
cTable.setMaximumSize(new java.awt.Dimension(650,140));
cTable.setShowGrid(true);
cTable.setPreferredSize(new java.awt.Dimension(650,140));
cTable.setPreferredScrollableViewportSize(new java.awt.Dimension(650,140));
cModel=new DefaultTableModel(20,2);
cTable.setModel(caseModel);
TableColumnModel cModel = cTable.getColumnModel();
TableColumn ta=cModel.getColumn(0);
ta.setHeaderValue("ID");
ta.setPreferredWidth(100);
TableColumn tb = cModel.getColumn(1);
tb.setPreferredWidth(10);
tb.setHeaderValue("Value");
cTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
if (ALLOW_ROW_SELECTION){// true by default
ListSelectionModel rowSM = caseStatTable.getSelectionModel();
rowSM.addListSelectionListener(new ListSelectionListener(){
publicvoid valueChanged(ListSelectionEvent e){
//Ignore extra messages.
if (e.getValueIsAdjusting())return;
ListSelectionModel lsm = (ListSelectionModel)e.getSource();
if (lsm.isSelectionEmpty()){
System.out.println("No rows are selected.");
}else{
int selectedRow = lsm.getMinSelectionIndex();
displayRow(cTable.getValueAt(selectedRow,0));
}
}
});
}else{
cTable.setRowSelectionAllowed(false);
}
}
return cTable;
}
the code of the displayRow method is below:
publicvoid displayRow(Object o){
if(oinstanceof String){
SDisplay sd=new SDisplay(this,(String)o);
sd.display();
}
}
and below is the SDisplay Dialog class:
publicclass SDisplayextends JDialogimplements Runnable{
privatestaticfinallong serialVersionUID = 1;
privateshort selectedOption = -1;
private JPanel jContentPane =null;
private JPanel btnPnl =null;
private JScrollPane displayPnl =null;
private JTextArea cInfo =null;
private JButton okBtn =null;
private JButton cnlBtn =null;
int x,y;
String cr=null;
public SDisplay(Frame owner,boolean modal){
super(owner);
initialize();
}
//PreviousClass is a user defined class that extends JInternalFrame
public SDisplay(PreviousClass jp, String cr){
x=jp.getLocationOnScreen().x;
y=jp.getLocationOnScreen().y;
this.cr=cr;
initialize();
}
/**
* This method initializes this
*
* @return void
*/
privatevoid initialize(){
this.setSize(500, 400);
this.setModal(true);
this.setTitle("Display");
this.setMaximumSize(new Dimension(500, 400));
this.setMinimumSize(new Dimension(500, 400));
this.setPreferredSize(new Dimension(500, 400));
this.setLocation(x,y);
this.setContentPane(getJContentPane());
this.setVisible(true);
}
/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getJContentPane(){
if (jContentPane ==null){
GridBagConstraints gridBagConstraints1 =new GridBagConstraints();
gridBagConstraints1.fill = GridBagConstraints.BOTH;
gridBagConstraints1.gridy = 0;
gridBagConstraints1.weightx = 1.0;
gridBagConstraints1.weighty = 1.0;
gridBagConstraints1.gridx = 0;
GridBagConstraints gridBagConstraints =new GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 1;
jContentPane =new JPanel();
jContentPane.setLayout(new GridBagLayout());
jContentPane.setPreferredSize(new Dimension(500, 400));
jContentPane.setMaximumSize(new Dimension(500, 400));
jContentPane.setMinimumSize(new Dimension(500, 400));
jContentPane.add(getBtnPnl(), gridBagConstraints);
jContentPane.add(getDisplayPnl(), gridBagConstraints1);
}
return jContentPane;
}
/**
* This method initializes btnPnl
*
* @return javax.swing.JPanel
*/
private JPanel getBtnPnl(){
if (btnPnl ==null){
try{
GridBagConstraints gridBagConstraints3 =new GridBagConstraints();
gridBagConstraints3.gridx = 1;
gridBagConstraints3.insets =new Insets(0, 50, 0, 0);
gridBagConstraints3.gridy = 0;
GridBagConstraints gridBagConstraints2 =new GridBagConstraints();
gridBagConstraints2.gridx = 0;
gridBagConstraints2.insets =new Insets(0, 0, 0, 50);
gridBagConstraints2.gridy = 0;
btnPnl =new JPanel();
btnPnl.setLayout(new GridBagLayout());
btnPnl.setMinimumSize(new Dimension(500, 50));
btnPnl.setMaximumSize(new Dimension(500, 50));
btnPnl.setPreferredSize(new Dimension(500, 50));
btnPnl.add(getOkBtn(), gridBagConstraints2);
btnPnl.add(getCnlBtn(), gridBagConstraints3);
}catch (java.lang.Throwable e){
// TODO: Something
}
}
return btnPnl;
}
/**
* This method initializes displayPnl
*
* @return javax.swing.JScrollPane
*/
private JScrollPane getDisplayPnl(){
if (displayPnl ==null){
try{
displayPnl =new JScrollPane();
displayPnl.setPreferredSize(new Dimension(500, 350));
displayPnl.setMaximumSize(new Dimension(500, 350));
displayPnl.setViewportView(getCInfo());
displayPnl.setMinimumSize(new Dimension(500, 350));
}catch (java.lang.Throwable e){
// TODO: Something
}
}
return displayPnl;
}
/**
* This method initializes cInfo
*
* @return javax.swing.JTextArea
*/
private JTextArea getCInfo(){
if (cInfo ==null){
try{
cInfo =new JTextArea();
cInfo.setSize(new Dimension(500, 350));
cInfo.setMaximumSize(new Dimension(500, 350));
cInfo.setPreferredSize(new Dimension(500, 350));
cInfo.setEditable(true);
cInfo.setLineWrap(true);
cInfo.setRows(100);
cInfo.setDoubleBuffered(true);
cInfo.setMinimumSize(new Dimension(500, 350));
}catch (java.lang.Throwable e){
// TODO: Something
}
}
return cInfo;
}
/**
* This method initializes okBtn
*
* @return javax.swing.JButton
*/
private JButton getOkBtn(){
if (okBtn ==null){
try{
okBtn =new JButton();
okBtn.setPreferredSize(new Dimension(70, 20));
okBtn.setMaximumSize(new Dimension(70, 20));
okBtn.setText("OK");
okBtn.setMinimumSize(new Dimension(70, 20));
okBtn.addActionListener(new ActionListener(){
publicvoid actionPerformed(ActionEvent event){
SDisplay.this.setVisible(false);
}
});
}catch (java.lang.Throwable e){
// TODO: Something
}
}
return okBtn;
}
/**
* This method initializes cnlBtn
*
* @return javax.swing.JButton
*/
private JButton getCnlBtn(){
if (cnlBtn ==null){
try{
cnlBtn =new JButton();
cnlBtn.setMinimumSize(new Dimension(70, 20));
cnlBtn.setPreferredSize(new Dimension(70, 20));
cnlBtn.setText("Close");
cnlBtn.setMaximumSize(new Dimension(70, 20));
cnlBtn.addActionListener(new ActionListener(){
publicvoid actionPerformed(ActionEvent event){
SDisplay.this.setVisible(false);
}
});
}catch (java.lang.Throwable e){
// TODO: Something
}
}
return cnlBtn;
}
publicvoid run(){
cInfo.append("String to append: "+cr);
caseInfo.append("\n");
}
publicvoid display(){
new Thread(this).start();
}
}
I implemented The SDisplay to use a Thread to append the text, so that appending is independent of any other process.
When I execute this code, the jtextarea does not display any appended text. Can anyone explain what i am doing wrong?
Regards

