Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Displaying comboboxes in tables





I'm using a table with JComboBox as renderer (public class ComboBoxRenderer implements TableCellRenderer { JComboBox c; ...) and I cannot make it look decent on Aqua.

How could I make it have the same height as a JTable field (it shows clipped, too big to fit). ? ref http://lists.apple.com/archives/Java- dev/2003/Dec/msg00045.html
How can I make it have the right look when it is focused and/or selected ? It now looks like a travestite label with an aqua arrow at the right !


It seems like the component knows better and rejects all my efforts to even change background color?


import java.awt.Color; import javax.swing.BorderFactory; import javax.swing.JComboBox; import javax.swing.JTable; import javax.swing.table.TableCellRenderer;

/**
 *
 * @author jdiaz
 */

//This sucks in OS X
public class ComboBoxRenderer  implements TableCellRenderer {
        JComboBox c;

private static final ComboBoxRenderer instance = new ComboBoxRenderer();

public static ComboBoxRenderer getInstance () { return instance; }

        Color co = new Color(180,180,255);
        Color co2 = new Color(255,0,255);

private ComboBoxRenderer() {
c = new JComboBox();
c.setEditable(true);
c.setBackground(Color.GRAY); //ignored
c.setBorder(BorderFactory.createEmptyBorder()); // ignored???
}


public java.awt.Component getTableCellRendererComponent (JTable table, Object value,
boolean isSelected, boolean hasFocus, int row, int column) {


/*
if (hasFocus) {
System.out.println("FOcus gained");
c.setForeground(co2);
c.setBackground(co); //table.getSelectionBackground());
}
if (isSelected) {
System.out.println(" IS SELECTED: fg" + table.getSelectionForeground() +
" bg " + table.getSelectionBackground());
//c.setForeground (table.getSelectionForeground());
//c.setBackground (table.getSelectionBackground());
} else {
c.setForeground(table.getForeground());
c.setBackground(table.getBackground());
}
*/
// Select the current value
c.setSelectedItem(value);
return c;
}
}


Code is commented because it does not seem to get anything useful done.
Should I just forget about it and display it like a label .... (DefaultTableCellRenderer) ?







_______________________________________________ Do not post admin requests to the list. They will be ignored. Java-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.