* Fixed ArrayIndexOutOfBoundsException by trying to do actions on tables removed meanwhile.

This commit is contained in:
LevelX2 2016-01-15 21:03:39 +01:00
parent acb57c0fc8
commit cdbda6a7e6

View file

@ -25,7 +25,6 @@
* authors and should not be interpreted as representing official policies, either expressed * authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com. * or implied, of BetaSteward_at_googlemail.com.
*/ */
package mage.client.util; package mage.client.util;
import java.awt.Component; import java.awt.Component;
@ -78,18 +77,13 @@ public class ButtonColumn extends AbstractCellEditor implements TableCellRendere
@Override @Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
if (hasFocus) if (hasFocus) {
{
renderButton.setForeground(table.getForeground()); renderButton.setForeground(table.getForeground());
renderButton.setBackground(UIManager.getColor("Button.background")); renderButton.setBackground(UIManager.getColor("Button.background"));
} } else if (isSelected) {
else if (isSelected)
{
renderButton.setForeground(table.getSelectionForeground()); renderButton.setForeground(table.getSelectionForeground());
renderButton.setBackground(table.getSelectionBackground()); renderButton.setBackground(table.getSelectionBackground());
} } else {
else
{
renderButton.setForeground(table.getForeground()); renderButton.setForeground(table.getForeground());
renderButton.setBackground(UIManager.getColor("Button.background")); renderButton.setBackground(UIManager.getColor("Button.background"));
} }
@ -107,35 +101,40 @@ public class ButtonColumn extends AbstractCellEditor implements TableCellRendere
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
if (table.getRowCount() >= table.getEditingRow()) {
int row = table.convertRowIndexToModel(table.getEditingRow()); int row = table.convertRowIndexToModel(table.getEditingRow());
fireEditingStopped(); fireEditingStopped();
ActionEvent event = new ActionEvent(table, ActionEvent.ACTION_PERFORMED, "" + row); ActionEvent event = new ActionEvent(table, ActionEvent.ACTION_PERFORMED, "" + row);
action.actionPerformed(event); action.actionPerformed(event);
}
} }
@Override @Override
public void mousePressed(MouseEvent arg0) { public void mousePressed(MouseEvent arg0) {
if (table.isEditing() && table.getCellEditor() == this) if (table.isEditing() && table.getCellEditor() == this) {
isButtonColumnEditor = true; isButtonColumnEditor = true;
} }
}
@Override @Override
public void mouseReleased(MouseEvent arg0) { public void mouseReleased(MouseEvent arg0) {
if (isButtonColumnEditor && table.isEditing()) if (isButtonColumnEditor && table.isEditing()) {
table.getCellEditor().stopCellEditing(); table.getCellEditor().stopCellEditing();
}
isButtonColumnEditor = false; isButtonColumnEditor = false;
} }
@Override @Override
public void mouseClicked(MouseEvent arg0) {} public void mouseClicked(MouseEvent arg0) {
}
@Override @Override
public void mouseEntered(MouseEvent arg0) {} public void mouseEntered(MouseEvent arg0) {
}
@Override @Override
public void mouseExited(MouseEvent arg0) {} public void mouseExited(MouseEvent arg0) {
}
} }