Last active
March 10, 2019 12:20
-
-
Save ezhov-da/ba863682501a19438974ec9ae2ce8466 to your computer and use it in GitHub Desktop.
java слушатель изменения столбцов jtable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[code:]java[:code] | |
/** | |
* Данный класс реализует слушателя на изменение любых свойств | |
* для изменения размеров фильтра. | |
* Его необходимо добавлять и к заголовку и к таблице, чтоб полностью | |
* контролировать размеры элементов | |
* <p> | |
* @author ezhov_da | |
*/ | |
class FilterResizePropertyChangeListener implements PropertyChangeListener | |
{ | |
JXTreeTable treeTable; | |
JTableHeader header; | |
JComponent[] massiveFilters; | |
int heightFilters; | |
/** | |
* Конструктор принимает: | |
* <p> | |
* @param treeTable - таблица, на которую ставятся фильтры | |
* @param massiveFilters - список фильтров для столбцов | |
* (их должно быть столько же, сколько и столбцов) | |
* @param heightFilters - высота фильтров | |
*/ | |
public FilterResizePropertyChangeListener(JXTreeTable treeTable, JComponent[] massiveFilters, int heightFilters) | |
{ | |
this.treeTable = treeTable; | |
this.massiveFilters = massiveFilters; | |
this.heightFilters = heightFilters; | |
header = treeTable.getTableHeader(); | |
} | |
@Override | |
public void propertyChange(PropertyChangeEvent evt) | |
{ | |
setSizeToTextField(); | |
} | |
protected void setSizeToTextField() | |
{ | |
Dimension dimension; | |
Rectangle rectangle; | |
int countColumn = treeTable.getColumnCount(); | |
for (int i = 0; i < countColumn; i++) | |
{ | |
JComponent component = massiveFilters[i]; | |
TableColumn tableColumn = treeTable.getColumn(i); | |
dimension = new Dimension(tableColumn.getWidth(), heightFilters); | |
rectangle = header.getHeaderRect(i); | |
component.setLocation(rectangle.x, component.getLocation().y); | |
component.setSize(dimension); | |
component.setMinimumSize(dimension); | |
component.setPreferredSize(dimension); | |
component.setMaximumSize(dimension); | |
} | |
} | |
} | |
[/code] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment