// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.ui;

import com.intellij.openapi.util.Pair;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.swing.table.JTableHeader;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumn;
import java.awt.*;

/**
 * @author Konstantin Bulenkov
 */
public class TableHeaderExpandableItemsHandler extends AbstractExpandableItemsHandler<TableColumn, JTableHeader> {
  protected TableHeaderExpandableItemsHandler(@NotNull JTableHeader component) {
    super(component);
  }

  @Override
  protected @Nullable Pair<Component, Rectangle> getCellRendererAndBounds(TableColumn column) {
    TableCellRenderer renderer = column.getHeaderRenderer();
    if (renderer == null) {
      renderer = myComponent.getDefaultRenderer();
    }
    boolean hasFocus = !myComponent.isPaintingForPrint() && myComponent.hasFocus();
    Component comp = renderer.getTableCellRendererComponent(myComponent.getTable(),
                                                            column.getHeaderValue(),
                                                            false, hasFocus,
                                                            -1, column.getModelIndex());

    Rectangle rect = myComponent.getHeaderRect(column.getModelIndex());
    return Pair.create(comp, rect);
  }

  @Override
  protected TableColumn getCellKeyForPoint(Point point) {
    int i = myComponent.columnAtPoint(point);
    if (i >= 0) {
      return myComponent.getColumnModel().getColumn(i);
    }
    return null;
  }
}

@@ -1360,16 +1360,65 @@
 ndex());
+%0A    AppUIUtil.targetToDevice(comp, myComponent);
 %0A%0A    Re
@@ -1479,24 +1479,72 @@
 elIndex());%0A
+    rect.width = comp.getPreferredSize().width;%0A
     return P

fix rectangle width for table header expander