From 3fb9dd1fa6020298e8c9610f90fa73a4247adc5e Mon Sep 17 00:00:00 2001 From: Nathan Cannon Date: Sat, 2 Apr 2016 19:06:49 +0100 Subject: [PATCH] Volume value is now padded to maintain ui element size. --- src/main/java/musicplayer/swingui/PlayerGUI.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/musicplayer/swingui/PlayerGUI.java b/src/main/java/musicplayer/swingui/PlayerGUI.java index 4aaa0ac..3f42d44 100644 --- a/src/main/java/musicplayer/swingui/PlayerGUI.java +++ b/src/main/java/musicplayer/swingui/PlayerGUI.java @@ -153,16 +153,21 @@ public class PlayerGUI extends JPanel implements PlayerCallbackInterface { volumeSlider.setValue(player.getVolume()); panel.add(volumeSlider); JLabel volumeValue = new JLabel(); - volumeValue.setText(String.format("%d%%", player.getVolume())); + volumeValue.setText(volumeFormat(player.getVolume())); volumeSlider.addChangeListener(e -> { player.setVolume(((JSlider) e.getSource()).getValue()); - volumeValue.setText(String.format("%d%%", player.getVolume())); + volumeValue.setText(volumeFormat(player.getVolume())); ConfigManager.setLastVolume(player.getVolume()); }); panel.add(volumeValue); return panel; } + private String volumeFormat(int volume){ + return String.format("%03d%%", volume); + + } + /** * Populate the top menu bar with items. */