Article View: borland.public.jbuilder.java.swing
Article #7815Re: JTable Questions
From: James A. Schulz
Date: Mon, 01 Jan 2001 13:52
Date: Mon, 01 Jan 2001 13:52
111 lines
3983 bytes
3983 bytes
Niall,
My table will function more or less as the old DOS character screen used to
do and it will display a diagram that my app will build one "cell" at a
time. Now and then I will need to "clear" the screen. Can you show me how
I would do that using the sort of hash table you describe?
thanks,
James
"Niall Pemberton" <Niall.Pemberton@btinternet.com> wrote in message
news:3a4fb895_1@dnews...
> James,
>
> your table cell renderer is strange...I'm not an expert but I don't think
> you need a setValue() method in it ... you need to implement a
> getTableCellRendererComponent() method as below, from your earlier post
you
> can determine the cell coordinates which are passed as arguments to the
> method. Otherwise your PcCharacter could be a class which contains the
> character value and colurs associated with it.
>
> public class PcCellRenderer extends DefaultTableCellRenderer {
>
> private JLabel blankLabel;
> private JLabel charLabel;
> private PcCharacter c;
>
> public Component getTableCellRendererComponent(JTable table, Object obj,
> boolean isSelected, boolean hasFocus, int row, int column) {
>
> if (obj == null)
> return blankLabel;
>
> c = (PcCharacter)obj;
> charLabel.setText(c.getValue());
> charLabel.setForeground(c.getForeground());
> charLabel.setBackground(c.getBackground());
> return charLabel;
>
> }
> }
>
> On the subject of initialising the values, you don't have to do it. Set up
> your own Table Model as below, using a HashMap to only store values when
you
> actually have one:
>
>
> public abstract class PcCellModel extends AbstractTableModel {
>
> private Map objectMatrix = new HashMap();
> private Point objectIndex = new Point(0,0);
>
> protected int maxCol = 55;
> protected int maxRow = 25;
>
> public PcCellModel () {
> }
>
> public PcCellModel (int row, int col) {
> maxRow = row;
> maxCol = col;
> }
>
> public Object getValueAt(int row, int col) {
> objectIndex.x = row;
> objectIndex.y = col;
>
> if (objectMatrix.get(objectIndex) == null)
> return null;
>
> return (PcCharacter)objectMatrix.get(objectIndex);
> }
>
> public void setValueAt(Object setObject, int row, int col) {
> if (setObject == null) {
> objectMatrix.remove(new Point(row, col));
> }
> else {
> maxCol = Math.max(col, maxCol);
> maxRow = Math.max(row, maxRow);
> objectMatrix.put(new Point(row, col), setObject);
> }
> }
>
> public int getRowCount() {
> return maxRow;
> }
> public int getColumnCount() {
> return maxCol;
> }
> public int getMaxColumn() {
> return maxCol;
> }
> public int getMaxRow() {
> return maxRow;
> }
>
> public boolean isCellEditable(int row, int col) {
> return false;
> }
>
> }
>
> I kind of cobbled this together but I hope it helps.
>
> Niall
>
>
Technical Details
Message-ID:
<92q1tg$8ur4@bornews.inprise.com>Path:
arc1-ca.pugleaf.net!supernews.google.com!sn-xit-02!supernews.com!newsfeed.direct.ca!look.ca!newsfeed.wirehub.nl!PeerFeed.KWeb.on.ca!bornews.borland.com!not-for-mailReferences:
<92lbpr$6ro1@bornews.inprise.com> <MPG.14b89345ccc5b0c7989e08@forums.borland.com> <92nedq$66a1@bornews.inprise.com> <3a4fb895_1@dnews>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,7fa15b59fdc30449 X-Google-Attributes: gid111d45,public X-Google-ArrivalTime: 2001-01-01 05:51:09 PST Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-02!supernews.com!newsfeed.direct.ca!look.ca!newsfeed.wirehub.nl!PeerFeed.KWeb.on.ca!bornews.borland.com!not-for-mail From: "James A. Schulz" <jaschulz@wiseware.com> Newsgroups: borland.public.jbuilder.java.swing Subject: Re: JTable Questions Date: Mon, 1 Jan 2001 07:52:32 -0600 Organization: Another Netscape Collabra Server User Lines: 113 Message-ID: <92q1tg$8ur4@bornews.inprise.com> References: <92lbpr$6ro1@bornews.inprise.com> <MPG.14b89345ccc5b0c7989e08@forums.borland.com> <92nedq$66a1@bornews.inprise.com> <3a4fb895_1@dnews> Reply-To: "James A. Schulz" <jaschulz@wiseware.com> NNTP-Posting-Host: 165.121.198.13 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4522.1200 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200