Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tooltips for truncated long labels in config dialog #893

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 33 additions & 7 deletions src/main/java/featurecat/lizzie/gui/ConfigDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -113,9 +114,9 @@ public class ConfigDialog extends JDialog {
private List<String> 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
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -1819,6 +1820,31 @@ protected void done() {
}
}

private class PanelWithToolTip extends JPanel {
public void add(JLabel label) {
String texts[] = label.getText().split("\n", 2);
String labelText = texts[0];
String toolTipText = (texts.length >= 2) ? texts[1] : labelText;
String displayedText =
SwingUtilities.layoutCompoundLabel(
label,
label.getFontMetrics(label.getFont()),
labelText,
label.getIcon(),
label.getVerticalAlignment(),
label.getHorizontalAlignment(),
label.getVerticalTextPosition(),
label.getHorizontalTextPosition(),
label.getBounds(),
label.getBounds(),
label.getBounds(),
label.getIconTextGap());
label.setText(labelText);
if (displayedText != toolTipText) label.setToolTipText(toolTipText);
super.add(label);
}
}

private String getEngineLine() {
String engineLine = "";
File engineFile = null;
Expand Down