Skip to content

Commit ff83b7a

Browse files
committed
Fix hardwired constants in Console dims. and Color widget
Console: Define height relative to font size currently in use. This ensures it adopts the same height as other widgets in hiDPI screens Console: Compute scroll Pane dimensions from font metrics. I.e., rather than using a hardwired dimension that does not scale well on HiDPI, use line/columns instead. SwingColorWidget: Do not use harwired height.
1 parent 4657d8a commit ff83b7a

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

src/main/java/org/scijava/ui/swing/console/ConsolePanel.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,12 @@ private synchronized void initGui() {
132132
textPanel.add(textPane);
133133

134134
scrollPane = new JScrollPane(textPanel);
135-
scrollPane.setPreferredSize(new Dimension(600, 600));
136135

137136
// Make the scroll bars move at a reasonable pace.
138-
final FontMetrics fm = scrollPane.getFontMetrics(scrollPane.getFont());
137+
final FontMetrics fm = scrollPane.getFontMetrics(textPane.getFont());
139138
final int charWidth = fm.charWidth('a');
140139
final int lineHeight = fm.getHeight();
140+
scrollPane.setPreferredSize(new Dimension(charWidth * 80, lineHeight * 10)); //80 columns, 10 lines
141141
scrollPane.getHorizontalScrollBar().setUnitIncrement(charWidth);
142142
scrollPane.getVerticalScrollBar().setUnitIncrement(2 * lineHeight);
143143
textPane.setComponentPopupMenu(initMenu());

src/main/java/org/scijava/ui/swing/widget/SwingColorWidget.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import javax.swing.JColorChooser;
4747
import javax.swing.JDialog;
4848
import javax.swing.JPanel;
49+
import javax.swing.UIManager;
4950
import javax.swing.colorchooser.AbstractColorChooserPanel;
5051

5152
import org.scijava.plugin.Plugin;
@@ -66,7 +67,7 @@ public class SwingColorWidget extends SwingInputWidget<ColorRGB> implements
6667
ActionListener, ColorWidget<JPanel>
6768
{
6869

69-
private static final int SWATCH_WIDTH = 64, SWATCH_HEIGHT = 16;
70+
private static final int SWATCH_WIDTH = 64, SWATCH_HEIGHT = widgetHeight();
7071

7172
private static final String HSB_CLASS_NAME =
7273
"javax.swing.colorchooser.DefaultHSBChooserPanel";
@@ -211,6 +212,15 @@ private int value(final Object o) {
211212
return chooser;
212213
}
213214

215+
private static int widgetHeight() {
216+
try {
217+
return UIManager.getFont("TextField.font").getSize();
218+
} catch (final Exception ignored) {
219+
// do nothing
220+
}
221+
return 16;
222+
}
223+
214224
// -- AbstractUIInputWidget methods ---
215225

216226
@Override

src/main/java/org/scijava/ui/swing/widget/SwingNumberWidget.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ else if (model.isStyle(NumberWidget.SLIDER_STYLE)) {
128128
}
129129
spinner.setEditor(new JSpinner.NumberEditor(spinner, format));
130130

131-
Dimension spinnerSize = spinner.getSize();
131+
Dimension spinnerSize = spinner.getPreferredSize();
132132
spinnerSize.width = 50;
133133
spinner.setPreferredSize(spinnerSize);
134134
fixSpinner(type);

0 commit comments

Comments
 (0)