Fix TreeTable row height for GTK+ L&F

This commit is contained in:
Roman Shevchenko
2011-06-27 20:56:14 +04:00
parent 307afacb96
commit bfa356bc72
2 changed files with 24 additions and 26 deletions
@@ -134,9 +134,9 @@ public class JBTable extends JTable implements ComponentWithEmptyText, Component
TableModel model = getModel();
for (int row = 0; row < model.getRowCount(); row++) {
for (int column = 0; column < model.getColumnCount(); column++) {
Dimension size =
getCellRenderer(row, column).getTableCellRendererComponent(this, model.getValueAt(row, column), true, true, row, column)
.getPreferredSize();
Dimension size = getCellRenderer(row, column)
.getTableCellRendererComponent(this, model.getValueAt(row, column), true, true, row, column)
.getPreferredSize();
myRowHeight = Math.max(size.height, myRowHeight);
}
}
@@ -153,18 +153,18 @@ public class JBTable extends JTable implements ComponentWithEmptyText, Component
return Math.max(myRowHeight, myMinRowHeight);
}
@Override
public void updateUI() {
super.updateUI();
myMinRowHeight = null;
}
@Override
public void setRowHeight(int rowHeight) {
myRowHeight = rowHeight;
myRowHeightIsExplicitlySet = true;
}
@Override
public void updateUI() {
super.updateUI();
myMinRowHeight = null;
}
private void repaintViewport() {
if (!isDisplayable() || !isVisible()) return;
@@ -260,7 +260,7 @@ public class JBTable extends JTable implements ComponentWithEmptyText, Component
public static DefaultCellEditor createBooleanEditor() {
return new DefaultCellEditor(new JCheckBox()) {
{
((JCheckBox)getComponent()).setHorizontalAlignment(JCheckBox.CENTER);
((JCheckBox)getComponent()).setHorizontalAlignment(SwingConstants.CENTER);
}
@Override
@@ -56,20 +56,18 @@ public class TreeTable extends JBTable {
@SuppressWarnings({"MethodOverloadsMethodOfSuperclass"})
public void setModel(TreeTableModel treeTableModel) {// Create the tree. It will be used as a renderer and editor.
if (myTree != null){
if (myTree != null) {
myTree.removePropertyChangeListener(JTree.ROW_HEIGHT_PROPERTY, myTreeRowHeightPropertyListener);
}
myTree = new TreeTableTree(treeTableModel, this);
if (myTree.getRowHeight() != getRowHeight()){
setRowHeight(myTree.getRowHeight());
}
setRowHeight(myTree.getRowHeight());
myTreeRowHeightPropertyListener = new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent evt) {
int treeRowHeight = myTree.getRowHeight();
if (treeRowHeight == getRowHeight() - 3) return;
setRowHeight(treeRowHeight);
}
};
public void propertyChange(PropertyChangeEvent evt) {
int treeRowHeight = myTree.getRowHeight();
if (treeRowHeight == getRowHeight() - 3) return;
setRowHeight(treeRowHeight);
}
};
myTree.addPropertyChangeListener(JTree.ROW_HEIGHT_PROPERTY, myTreeRowHeightPropertyListener);
// Install a tableModel representing the visible rows in the tree.
@@ -90,13 +88,13 @@ public class TreeTable extends JBTable {
// No intercell spacing
setIntercellSpacing(new Dimension(0, 0));
// And update the height of the trees row to match that of
// the table.
// And update the height of the trees row to match that of the table.
if (myTree.getRowHeight() < 1) {
// Metal looks better like this.
setRowHeight(18);
setRowHeight(18); // Metal looks better like this.
}
else {
setRowHeight(getRowHeight());
}
setRowHeight(getRowHeight());
}
public TreeTableModel getTableModel() {
@@ -122,7 +120,7 @@ public class TreeTable extends JBTable {
/**
* Overridden to message super and forward the method to the tree.
* Since the tree is not actually in the component hieachy it will
* Since the tree is not actually in the component hierarchy it will
* never receive this unless we forward it in this manner.
*/
public void updateUI() {