Article View: borland.public.jbuilder.java.swing
Article #708lost text
From: Alan Shiers
Date: Wed, 29 Dec 2004 19:57
Date: Wed, 29 Dec 2004 19:57
102 lines
4191 bytes
4191 bytes
Hi there,
In my project I save objects to file. One such object I call Listbox. It
extends JScrollPane and its viewport contains a JList.
It looks like so:
public class Listbox extends JScrollPane implements InputTool, Serializable
{
private JList list = null;
private String id = "";
private String[] values = null;
private static final String[] EMPTY_ARRAY = new String[0];
private boolean haveValues;
private int item = 0; //default
private InputType type = null;
public Listbox()
{
list = new JList();
super.getViewport().add(list);
list.setVisibleRowCount(4);
setPreferredSize(new Dimension(140,90));
setMaximumSize(new Dimension(140,90));
ItemListener listener = new ItemListener();
list.addMouseListener(listener);
setMultipleSelect(false);//default
}
...
}
In my SaveFile() method using SwingUtilities.invokeLater() method (see
below), I can save all the objects to file alright, but the text in my
Listbox keeps disappearing. I have tried calling repaint(), revalidate() on
both Listbox and the JList it contains, but neither works. The text is
there, it just isn't showing after a save. What am I doing wrong?
Alan
*********************************************
public void SaveFile()
{
//if FileOpen is blank then we know that the DocumentPanel
//hasn't been saved as a particular file yet. So, we move along
//to SaveFileAs() method in this case.
if(FileOpen.equals(""))
{
SaveFileAs();
return;
}
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
FileOutputStream fStream = null;
ObjectOutputStream stream = null;
try
{
File file = new File(FileOpen);
if(file.exists())
{
fStream = new FileOutputStream(file);
stream = new ObjectOutputStream(fStream);
stream.writeObject(docPanel);
}
}
catch(Exception ex)
{
ex.printStackTrace();
JOptionPane.showMessageDialog(JTestComposer.this, "Save
Error: " + ex.toString(),
"Warning", JOptionPane.WARNING_MESSAGE);
}
finally
{
try
{
if(stream != null)
stream.close();
if(fStream != null)
fStream.close();
InputType type = null;
for(int i = 1; i <= docPanel.getTable().getRowCount();
i++)
{
type =
docPanel.getTable().getTableRow(i).getTargetPanel().getInputType();
if(type == InputType.LISTBOX)
{
Listbox list =
(Listbox)docPanel.getTable().getTableRow(i).getTargetPanel().getComponent(0)
;
list.revalidate(); //<< this is where I'm trying to
get the text to reappear
}
}
}
catch(IOException ioe){}
}
}
});
}
Technical Details
Message-ID:
<41d30d52$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.maxwell.syr.edu!transit.news.xs4all.nl!border2.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!pe2.news.blueyonder.co.uk!blueyonder!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 111d45,a60f7bec7c6371ad,start X-Google-Attributes: gid111d45,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Alan Shiers" <ashiers@hfx.eastlink.ca> Newsgroups: borland.public.jbuilder.java.swing Subject: lost text Date: Wed, 29 Dec 2004 15:57:58 -0400 Lines: 104 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1437 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 NNTP-Posting-Host: 24.222.101.2 Message-ID: <41d30d52$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1104350546 24.222.101.2 (29 Dec 2004 12:02:26 -0800) Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.maxwell.syr.edu!transit.news.xs4all.nl!border2.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!pe2.news.blueyonder.co.uk!blueyonder!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail