myJdbComboBox.setRenderer(new ComboBoxRenderer())
.
.
.
class ComboBoxRenderer extends JLabel implements ListCellRenderer {
public Component getListCellRendererComponent(JList list, Object
value, int index, boolean isSelected, boolean cellHasFocus) {
//Get the selected index. (The index param isn't
//always valid, so just use the value.)
if( value != null){
if (isSelected) {
list.setToolTipText(value.toString());
setBackground(list.getSelectionBackground());
setForeground(list.getSelectionForeground());
}
else {
setBackground(list.getBackground());
setForeground(list.getForeground());
}
this.setText( value.toString() );
}
return this;
}
}
....
I also tried....
class ComboBoxRenderer2 extends JLabel implements TableCellRenderer,
ListCellRenderer {.....}
class ComboBoxRenderer2 extends DBCellRenderer implements
ListCellRenderer{....}
class ComboBoxRenderer2 extends BasicComboBoxRenderer{...}
none of which worked. Maybe I am completely lost as to how JdbComboBox
implements its renderer. The toolTip simply does not popup, but the
toolTip value will be set though.
thank you for your help...
n
Well, after much research and reading, testing,etc... The best solution
is to create your own JComboBox and not to use JDBComboBox.
Mine works like so:
public class JComboBox_Client
extends JComboBox {
public JComboBox_Client() {
try {
jbInit();
}
catch (Exception ex) {
ex.printStackTrace();
}
}
private void jbInit() throws Exception {
this.setRenderer(new MyComboBoxRendererLocal());
this.queryRefresh();
this.setMinimumSize(new Dimension(275, 22));
this.setPreferredSize(new Dimension(400, 22));
this.setSelectedItem(null);
}
public Strnig get_Client_Desc(){
return ((PickListItem)this.getSelectedItem()).getDesc();
}
public String get_Client_Name(){
return ((PickListItem)this.getSelectedItem()).getDisplayName();
}
public BigDecimal get_Client_ID() {
return ((PickListItem)this.getSelectedItem()).getID();
}
public void reset_CompanyAgency() {
this.setSelectedIndex( -1);
this.setSelectedItem(null);
}
public void queryRefresh(){
this.removeAllItems();
ResultSet crSet = null;
try {
crSet = new CachedRowSetImpl();
crSet = myDB.createStatement().executeQuery(query);
crSet.beforeFirst();
this.addItem(new PickListItem(new BigDecimal(-1), ""));
while (crSet.next()) {
this.addItem(new
PickListItem(crSet.getBigDecimal("CLIENT_ID"),
crSet.getString("CLIENT_NAME"),
crSet.getString("CLIENT_DESC"));
}
}
catch (SQLException ex) {
ex.printStackTrace();
}
}
public void setSelectedByClientId(BigDecimal CLIENT_ID){
for (int i = 0; i < this.getItemCount(); i++) {
if ( ((PickListItem)this.getItemAt(i)).getID().equals(CLIENT_ID)) {
this.setSelectedIndex(i);
}
}
}
class MyComboBoxRendererLocal extends JLabel implements
ListCellRenderer {
public MyComboBoxRendererLocal() {
setOpaque(true);
}
public Component getListCellRendererComponent(JList list, Object value,
int index, boolean
isSelected,
boolean cellHasFocus) {
if ( value != null ){
if (isSelected) {
setForeground(list.getSelectionForeground());
super.setBackground(list.getSelectionBackground());
}
else {
setForeground(list.getForeground());
setBackground(list.getBackground());
}
// Select the current value
setText(((PickListItem) value).getDisplayName().toString());
setToolTipText(((PickListItem)value).getDesc());
}
return this;
}
}
private final String query = "SELECT CLIENT_ID, CLIENT_NAME,
CLIENT_DESC FROM PS_CLIENT_LOOKUP";
private Database myDB = new Database(); //this is your DB conn.
PickListItem listItem = new PickListItem(new BigDecimal(-1), "null");
}
///////Data Type PickListItem
public class PickListItem {
private final BigDecimal id;
private final String displayName;
private final String description;
public PickListItem(BigDecimal id, String displayName, String
description) {
this.id = id;
this.displayName = displayName;
this.description = description;
}
public String getDesc(){
return this.description;
}
public BigDecimal getID(){
return this.id;
}
public String getDisplayName(){
return this.displayName;
}
}
------------------------------------------------------
> Well, after much research and reading, testing,etc... The best solution
> is to create your own JComboBox and not to use JDBComboBox.
>
> Mine works like so: [...]
Thanks for contributing your solution. I don't use dbSwing, and
don't even do any UI programming these days, but it's good to see
it when someone does a lot of work and makes an effort to
contribute back to the community.
--
Paul Furbacher (TeamB)
Save time, search the archives:
http://info.borland.com/newsgroups/ngsearch.html
Is it in Joi Ellis's Faq-O-Matic?
http://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.