# HG changeset patch # User Matti Hamalainen # Date 1556106807 -10800 # Node ID b88440f4431a6bdc5baa7254349b0e547735b5dd # Parent f3302a2d7815954b5baf2d0d3c004c7634b62b23 Allow no-text (null text) buttons. diff -r f3302a2d7815 -r b88440f4431a game/IDMButton.java --- a/game/IDMButton.java Wed Apr 24 12:55:54 2019 +0300 +++ b/game/IDMButton.java Wed Apr 24 14:53:27 2019 +0300 @@ -112,16 +112,20 @@ img = imgUnpressed; } - if (metrics == null) - metrics = g.getFontMetrics(font); + g.drawImage(img, getScaledX() + xoffs, getScaledY() + yoffs, null); + + if (text != null) + { + if (metrics == null) + metrics = g.getFontMetrics(font); - int textWidth = metrics.stringWidth(text); - g.drawImage(img, getScaledX() + xoffs, getScaledY() + yoffs, null); - g.setFont(font); - g.setPaint(Color.black); - g.drawString(text, - getScaledX() + xoffs + (getScaledWidth() - textWidth) / 2, - getScaledY() + yoffs + getScaledHeight() / 2); + int textWidth = metrics.stringWidth(text); + g.setFont(font); + g.setPaint(Color.black); + g.drawString(text, + getScaledX() + xoffs + (getScaledWidth() - textWidth) / 2, + getScaledY() + yoffs + getScaledHeight() / 2); + } }