Board index » jbuilder » duplicating Properties Dialog box

duplicating Properties Dialog box


2004-12-14 04:39:35 AM
jbuilder19
Hi there,
Wondering if anyone there has duplicated a properties dialog box before. I
need to do exactly that for a project I'm working on. You know what I mean,
eh? The kind you can find in JBuilder. The one there is obviously using a
Tab control...one tab for properties and the other for events. The one I
intend to make doesn't need a Tab control. I'm only displaying properties,
no events.
So, I'm going to need a JScrollPane, but what would you recommend I use to
get the two columned list that one typically sees in a properties dialog
box? The two columned list generally shows the property name in the left
column and either provides a textfield in the second column or a button that
opens a more detailed dialog box for that particular property.
Any suggestions?
Alan
 
 

Re:duplicating Properties Dialog box

Alan Shiers wrote:
Quote
[...] a properties dialog box [...] I'm only displaying properties [...]

So, I'm going to need a JScrollPane, but what would you recommend I use to
get the two columned list that one typically sees in a properties dialog
box? The two columned list generally shows the property name in the left
column and either provides a textfield in the second column or a button that
opens a more detailed dialog box for that particular property.

Any suggestions?
Have you thought about using a JTable? The first
column isn't editable, so you'd use a JLabel as
the renderer, setting its fore/back colors appropriately.
For getting the appropriate editor in the second column,
you would probably override JTable.getCellEditor(row, col)
to return the appropriate editor component.
Also, the following Web site may provide some
insight:
johnchildress.com/tame/
See the JTable demos (the source code is available).
Not all the links work correctly, but you can manually
change them to get to where you want to go.
--
Paul Furbacher (TeamB)
Save time, search the archives:
www.borland.com/newsgroups/ngsearch.html
Is it in Joi Ellis's Faq-O-Matic?
www.visi.com/~gyles19/fom-serve/cache/1.html
Finally, please send responses to the newsgroup only.
That means, do not send email directly to me.
Thank you.
 

Re:duplicating Properties Dialog box

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);
}
});
}
}
 

{smallsort}

Re:duplicating Properties Dialog box

Alan Shiers wrote:
Quote
I'm going to have to approach this one step at a time, only becouse
constructing a JTable appears to be no small feat.
It's less daunting than you might think. And
I get the feeling that you aren't using all
the resources available to you. Use the force,
Luke.
Quote
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?
Well, a quick look at the JavaDoc for JTable yields
public boolean isCellEditable(int row, int col);
What about sub-classing and overriding that method
as follows in order to make column 0 non-editable?
public boolean isCellEditable(int row, int col) {
return ( col != 0);
}
I'm curious. Are you using JBuilder to its full
advantage by drilling down into classes such as
JTable, and then flipping to the "Doc" tab to
read the JavaDoc. You really have to adopt this
habit of work.
Also, are you using Google? A quick, simple search
on
jtable tutorial
netted the Swing tutorial which actually discusses
this kind of stuff.
An even more specific search would be
jtable tutorial property editor
Lo and behold the third hit
www.javaworld.com/javaworld/javatips/jw-javatip102.html
I'd say that's dead on target.
--
Paul Furbacher (TeamB)
Save time, search the archives:
www.borland.com/newsgroups/ngsearch.html
Is it in Joi Ellis's Faq-O-Matic?
www.visi.com/~gyles19/fom-serve/cache/1.html
Finally, please send responses to the newsgroup only.
That means, do not send email directly to me.
Thank you.