From 10a122f6afb8e3bd7c0bc9edd83109b26f512f29 Mon Sep 17 00:00:00 2001 From: dzmipt Date: Wed, 18 Dec 2024 20:14:54 +0100 Subject: [PATCH] decimal formating --- src/studio/ui/chart/Editor.java | 2 +- src/studio/ui/chart/NumericEditor.java | 5 ++++- src/studio/ui/chart/TimespanEditor.java | 5 ++++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/studio/ui/chart/Editor.java b/src/studio/ui/chart/Editor.java index f9f940f..fd9fda7 100644 --- a/src/studio/ui/chart/Editor.java +++ b/src/studio/ui/chart/Editor.java @@ -70,7 +70,7 @@ protected void notifyValueChanged() { } } - protected final JTextField txtValue = new JTextField(); + protected final JTextField txtValue = new JTextField(15); private double value = Double.NaN; diff --git a/src/studio/ui/chart/NumericEditor.java b/src/studio/ui/chart/NumericEditor.java index 57b090a..06b12e4 100644 --- a/src/studio/ui/chart/NumericEditor.java +++ b/src/studio/ui/chart/NumericEditor.java @@ -1,9 +1,12 @@ package studio.ui.chart; +import java.text.DecimalFormat; + public class NumericEditor extends Editor { + private static final DecimalFormat df7 = new DecimalFormat("#.#######"); protected void refresh() { - txtValue.setText("" + getValue()); + txtValue.setText(df7.format(getValue())); } @Override diff --git a/src/studio/ui/chart/TimespanEditor.java b/src/studio/ui/chart/TimespanEditor.java index cc621c8..7616a23 100644 --- a/src/studio/ui/chart/TimespanEditor.java +++ b/src/studio/ui/chart/TimespanEditor.java @@ -5,10 +5,13 @@ import javax.swing.*; import java.awt.*; +import java.text.DecimalFormat; import java.time.temporal.ChronoUnit; public class TimespanEditor extends Editor { + private static final DecimalFormat df5 = new DecimalFormat("#.#####"); + private final KType unitType; private K.KTimespan timespan = K.KTimespan.NULL; private final JComboBox comboUnit = @@ -56,7 +59,7 @@ public double getValue() { } protected void refresh() { - txtValue.setText("" + timespan.toUnitValue((ChronoUnit) comboUnit.getSelectedItem())); + txtValue.setText(df5.format(timespan.toUnitValue((ChronoUnit) comboUnit.getSelectedItem()))); } @Override