Article View: borland.public.jbuilder.java.swing
Article #757Re: duplicating Properties Dialog box
From: Alan Shiers
Date: Tue, 14 Dec 2004 17:49
Date: Tue, 14 Dec 2004 17:49
59 lines
2935 bytes
2935 bytes
Hi Paul,
I'm going to have to approach this one step at a time, only becouse
constructing a JTable appears to be no small feat.
So I thought to start out by creating a small practice example that makes
all cells in the table of type JLabel. According to what I've read the
DefaultTableCellRenderer extends JLabel, so it would appear I won't have to
make my own.
I threw together the following program in an attempt to use
DefaultTableCellRenderer and have all the cells of the table un-editable
(that being the case with JLabel). However, it didn't perform as I had
hoped. When I ran it, each cell was still editable! Perhaps you can explain
why that is, and what I need to do to fix it?
Alan
***********************************
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;
public class JLabelTableExample extends JFrame {
public JLabelTableExample(){
super( "JLabelTable Example" );
DefaultTableModel dm = new DefaultTableModel();
dm.setDataVector(new Object[][]{{"Label 1","foo"},
{"Label 2","bar"}},
new Object[]{"Property","Value"});
JTable table = new JTable();
table.setAutoCreateColumnsFromModel(false);
table.setModel(dm);
for(int i = 0; i < 2; i++)
{
DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
TableColumn column = new TableColumn(i,100,renderer,null);
table.addColumn(column);
}
JScrollPane scroll = new JScrollPane(table);
getContentPane().add( scroll );
setSize( 400, 100 );
setVisible(true);
}
public static void main(String[] args) {
JLabelTableExample frame = new JLabelTableExample();
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
}
Technical Details
Message-ID:
<41bf2893@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!news.netcologne.de!newsfeed-fusi.netcologne.de!border2.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-mailReferences:
<41bdfeec$1@newsgroups.borland.com> <41be143b@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 111d45,f02e9216364acd50 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 References: <41bdfeec$1@newsgroups.borland.com> <41be143b@newsgroups.borland.com> Subject: Re: duplicating Properties Dialog box Date: Tue, 14 Dec 2004 13:49:29 -0400 Lines: 61 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: <41bf2893@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1103046803 24.222.101.2 (14 Dec 2004 09:53:23 -0800) Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!news.netcologne.de!newsfeed-fusi.netcologne.de!border2.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