From 17212bbfde1fa96a08b3c3e6116813d14118b6a3 Mon Sep 17 00:00:00 2001 From: Hiraoka Date: Thu, 26 Aug 2021 20:19:35 +0900 Subject: [PATCH] Add tooltips for truncated long labels in config dialog --- .../featurecat/lizzie/gui/ConfigDialog.java | 37 +++++++++++++++---- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/src/main/java/featurecat/lizzie/gui/ConfigDialog.java b/src/main/java/featurecat/lizzie/gui/ConfigDialog.java index a0d50074e..68d0bf9c7 100644 --- a/src/main/java/featurecat/lizzie/gui/ConfigDialog.java +++ b/src/main/java/featurecat/lizzie/gui/ConfigDialog.java @@ -82,6 +82,7 @@ import javax.swing.ListCellRenderer; import javax.swing.SpinnerNumberModel; import javax.swing.SwingConstants; +import javax.swing.SwingUtilities; import javax.swing.SwingWorker; import javax.swing.border.Border; import javax.swing.event.ChangeEvent; @@ -113,9 +114,9 @@ public class ConfigDialog extends JDialog { private List fontList; private Theme theme; - public JPanel uiTab; - public JPanel themeTab; - public JPanel aboutTab; + public PanelWithToolTip uiTab; + public PanelWithToolTip themeTab; + public PanelWithToolTip aboutTab; public JButton okButton; // Engine Tab @@ -256,7 +257,7 @@ public void actionPerformed(ActionEvent e) { tabbedPane = new JTabbedPane(JTabbedPane.TOP); getContentPane().add(tabbedPane, BorderLayout.CENTER); - JPanel engineTab = new JPanel(); + PanelWithToolTip engineTab = new PanelWithToolTip(); tabbedPane.addTab(resourceBundle.getString("LizzieConfig.title.engine"), null, engineTab, null); engineTab.setLayout(null); @@ -658,17 +659,17 @@ protected DocumentFilter getDocumentFilter() { chkPrintEngineLog.setBounds(167, 425, 201, 23); engineTab.add(chkPrintEngineLog); - uiTab = new JPanel(); + uiTab = new PanelWithToolTip(); tabbedPane.addTab(resourceBundle.getString("LizzieConfig.title.ui"), null, uiTab, null); uiTab.setLayout(null); // Theme Tab - themeTab = new JPanel(); + themeTab = new PanelWithToolTip(); tabbedPane.addTab(resourceBundle.getString("LizzieConfig.title.theme"), null, themeTab, null); themeTab.setLayout(null); // About Tab - aboutTab = new JPanel(); + aboutTab = new PanelWithToolTip(); tabbedPane.addTab(resourceBundle.getString("LizzieConfig.title.about"), null, aboutTab, null); JLabel lblLizzieName = new JLabel("Lizzie " + Lizzie.lizzieVersion); @@ -1819,6 +1820,28 @@ protected void done() { } } + private class PanelWithToolTip extends JPanel { + public void add(JLabel label) { + super.add(label); + String text = label.getText(); + String displayedText = + SwingUtilities.layoutCompoundLabel( + label, + label.getFontMetrics(label.getFont()), + text, + label.getIcon(), + label.getVerticalAlignment(), + label.getHorizontalAlignment(), + label.getVerticalTextPosition(), + label.getHorizontalTextPosition(), + label.getBounds(), + label.getBounds(), + label.getBounds(), + label.getIconTextGap()); + if (displayedText != text) label.setToolTipText(text); + } + } + private String getEngineLine() { String engineLine = ""; File engineFile = null;