Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #23535
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!mx05.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Eric Sosman <esosman@comcast-dot-net.invalid> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: 5th col dies, cols 6 thru 15 move 1 col left, 15th col is born |
| Date | Sat, 20 Apr 2013 14:14:45 -0400 |
| Organization | A noiseless patient Spider |
| Lines | 60 |
| Message-ID | <kkulp2$v0f$1@dont-email.me> (permalink) |
| References | <300a4c2f-daba-4007-8551-3b1d0f263d27@googlegroups.com> <kkubde$jhq$1@dont-email.me> <98b6f34a-4162-472a-a740-91e86c1b3217@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| Injection-Date | Sat, 20 Apr 2013 18:11:46 +0000 (UTC) |
| Injection-Info | mx05.eternal-september.org; posting-host="0d73d8cc209bff1c6395088b400d0605"; logging-data="31759"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18tZJz0+HI9xu019c9Ut5yz" |
| User-Agent | Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20130328 Thunderbird/17.0.5 |
| In-Reply-To | <98b6f34a-4162-472a-a740-91e86c1b3217@googlegroups.com> |
| Cancel-Lock | sha1:c4BWVrDkF64ASrux/TRIHw0NXcI= |
| Xref | csiph.com comp.lang.java.programmer:23535 |
Show key headers only | View raw
On 4/20/2013 12:02 PM, clusa@aol.com wrote:
>> On Saturday, April 20, 2013 11:17:52 AM UTC-4, Eric Sosman wrote:
>> JTable should be straightforward. You'd extend AbstractTableModel to handle
>> the "sliding," calling fireTableDataChanged() to update the display.
>> Conveniences like scrolling would come for free (almost), and the JTable's
>> display might well be more efficient than managing 4500 JLabels. No, I don't
>> have example code. -- Eric Sosman esosman@comcast-dot-net.invalid
>
> I would also be able to eloquently color specific cells.
You can be as eloquent as you like with a TableCellRenderer,
most likely an extension of DefaultTableCellRenderer. This time,
I've got some example code (not eloquent, and not colorized, but
it should demonstrate the approach):
/**
* A {@code TableCellRenderer} that centers displayed text.
*/
class CenteredRenderer extends DefaultTableCellRenderer {
private static CenteredRenderer instance;
static CenteredRenderer instance() {
if (instance == null) {
instance = new CenteredRenderer();
}
return instance;
}
private CenteredRenderer() {
assert SwingUtilities.isEventDispatchThread();
}
@Override
public Component getTableCellRendererComponent(JTable table,
Object value, boolean select, boolean focus, int row, int col) {
assert SwingUtilities.isEventDispatchThread();
Component comp = super.getTableCellRendererComponent(table,
value, select, focus, row, col);
if (comp instanceof JLabel) {
((JLabel) comp).setHorizontalAlignment(SwingConstants.CENTER);
}
return comp;
}
}
I use it this way, in the constructor of a class extending
JTable:
TableColumnModel colmod = getColumnModel();
for (int c = 0; c < COLUMNS; ++c) {
TableColumn col = colmod.getColumn(c);
if ( /* I want this column centered ... */ ) {
col.setCellRenderer(CenteredRenderer.instance());
}
}
--
Eric Sosman
esosman@comcast-dot-net.invalid
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Find similar | Unroll thread
5th col dies, cols 6 thru 15 move 1 col left, 15th col is born clusardi2k@aol.com - 2013-04-19 16:54 -0700
Re: 5th col dies, cols 6 thru 15 move 1 col left, 15th col is born Knute Johnson <nospam@knutejohnson.com> - 2013-04-19 17:03 -0700
Re: 5th col dies, cols 6 thru 15 move 1 col left, 15th col is born "clusa@aol.com" <clusardi2k@aol.com> - 2013-04-19 17:29 -0700
Re: 5th col dies, cols 6 thru 15 move 1 col left, 15th col is born "clusa@aol.com" <clusardi2k@aol.com> - 2013-04-19 22:29 -0700
Re: 5th col dies, cols 6 thru 15 move 1 col left, 15th col is born Knute Johnson <nospam@knutejohnson.com> - 2013-04-20 09:02 -0700
[OT] Re: 5th col dies, cols 6 thru 15 move 1 col left, 15th col is born Manuel Collado <m.collado@domain.invalid> - 2013-04-20 16:44 +0200
Re: 5th col dies, cols 6 thru 15 move 1 col left, 15th col is born Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-04-20 11:17 -0400
Re: 5th col dies, cols 6 thru 15 move 1 col left, 15th col is born "clusa@aol.com" <clusardi2k@aol.com> - 2013-04-20 09:02 -0700
Re: 5th col dies, cols 6 thru 15 move 1 col left, 15th col is born Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-04-20 14:14 -0400
csiph-web