# Power Table - Dropdown Configuration

**URL:** <https://forum.inductiveautomation.com/t/power-table-dropdown-configuration/74682>\
**Category:** Ignition\
**Tags:** ignition81, vision, scripting\
**Created:** [June 7, 2023, 6:35am UTC](https://forum.inductiveautomation.com/t/power-table-dropdown-configuration/74682 "2023-06-07T06:35:52Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [June 9, 2023, 7:26am UTC](https://forum.inductiveautomation.com/t/power-table-dropdown-configuration/74682/6 "2023-06-09T07:26:08Z")

</div>

**Update:** I figured out how to dynamically set the dropdown menu widths to the width of the longest text item in the list.

**Here is the result:**  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/c/4/c4347bc868768d168ff32071451cca232a8b19f9.png)

The main problem was that the scroll pane had a maximum width setting that was equal to the cell size. After fixing this, code had to be added to ensure that the JComboBox was showing and the dropdown menu was open prior to the changes being applied.

Here is the ~~working~~ script:

> **Second Attempt Script**
>
> ```auto
> #def onMouseClick(self, [...], event):
> from javax.swing import JComboBox, JScrollPane
> from java.awt import Dimension
> from java.awt.font import FontRenderContext, TextLayout
> from java.awt import Font
> def setSizes(dropdown):
> dropdown.setMaximumSize(Dimension(2*maxItemWidth, 2*dropdown.getPreferredSize().height))
> dropdown.setMinimumSize(Dimension(0, 0))
> dropdown.setPreferredSize(Dimension(maxItemWidth, dropdown.getPreferredSize().height))
> for component in dropdown.getComponents():
> if isinstance(component, JScrollPane):
> setSizes(component)
> break
> if hasattr(self.table.getCellEditor(rowIndex, colIndex), 'component'):
> editorComponent = self.table.getCellEditor(rowIndex, colIndex).component
> if isinstance(editorComponent, JComboBox):
> tableFont = self.font
> widthSettingFont = Font(Font.MONOSPACED, tableFont.style, tableFont.size)
> dropdown = editorComponent.getUI().getAccessibleChild(editorComponent, 0)
> items = [
> editorComponent.renderer.getListCellRendererComponent(dropdown.getList(), editorComponent.model.getElementAt(row), -1, False, False).getText()
> for row in xrange(editorComponent.model.size)
> ]
> maxItemWidth = int(TextLayout(max(items, key=len), widthSettingFont, FontRenderContext(None, False, False)).bounds.width)
> if not editorComponent.popupVisible and editorComponent.showing:
> editorComponent.setPopupVisible(True)
> setSizes(dropdown)
> 
> ```

**Edit:** This script has a bug where if you click on the same cell multiple times the dropdown regresses due to the way the cell retains focus and prevents the mouseClick extension function from firing every time. **See [post 25](https://forum.inductiveautomation.com/t/power-table-dropdown-configuration/74682/25) for the updated solution.**

---

_[View the full topic](https://forum.inductiveautomation.com/t/power-table-dropdown-configuration/74682)._
