Example usage for javax.swing JTextField addCaretListener

List of usage examples for javax.swing JTextField addCaretListener

Introduction

In this page you can find the example usage for javax.swing JTextField addCaretListener.

Prototype

public void addCaretListener(CaretListener listener) 

Source Link

Document

Adds a caret listener for notification of any changes to the caret.

Usage

From source file:CaretEeventListener.java

public static void main(String[] a) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JTextField textField = new JTextField();

    textField.addCaretListener(new CaretListener() {

        public void caretUpdate(CaretEvent e) {
            System.out.println(e);

        }/*ww w .  j a  va 2  s . co  m*/
    });

    frame.add(new JScrollPane(textField));

    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String args[]) {
    final JTextField textField = new JTextField(15);
    JButton buttonCut = new JButton("Cut");
    JButton buttonPaste = new JButton("Paste");
    JButton buttonCopy = new JButton("Copy");

    JFrame jfrm = new JFrame("Cut, Copy, and Paste");
    jfrm.setLayout(new FlowLayout());
    jfrm.setSize(230, 150);//w w w.j a  v a  2  s . c  o m
    jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    buttonCut.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent le) {
            textField.cut();
        }
    });

    buttonPaste.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent le) {
            textField.paste();
        }
    });

    buttonCopy.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent le) {
            textField.copy();
        }
    });

    textField.addCaretListener(new CaretListener() {
        public void caretUpdate(CaretEvent ce) {
            System.out.println("All text: " + textField.getText());
            if (textField.getSelectedText() != null)
                System.out.println("Selected text: " + textField.getSelectedText());
            else
                System.out.println("Selected text: ");
        }
    });

    jfrm.add(textField);
    jfrm.add(buttonCut);
    jfrm.add(buttonPaste);
    jfrm.add(buttonCopy);
    jfrm.setVisible(true);
}

From source file:io.github.jeremgamer.editor.panels.components.ButtonPanel.java

public ButtonPanel(JFrame frame) {

    this.frame = frame;
    this.setSize(new Dimension(395, frame.getHeight() - 27 - 23));
    this.setLocation(300, 0);
    this.setBorder(BorderFactory.createTitledBorder("Edition du bouton"));
    this.setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));

    JLabel nameLabel = new JLabel("Nom : ");
    name.setPreferredSize(new Dimension(this.getWidth() - 285, 30));
    name.setEditable(false);/*from w  w  w .j a  v a  2  s . c o m*/
    JPanel namePanel = new JPanel();
    namePanel.add(nameLabel);
    namePanel.add(name);
    JPanel textPanel = new JPanel();
    JPanel nameAndTextPanel = new JPanel();
    JLabel textLabel = new JLabel("Texte :");
    CaretListener caretUpdateText = new CaretListener() {
        public void caretUpdate(javax.swing.event.CaretEvent e) {
            JTextField text = (JTextField) e.getSource();
            bs.set("text", text.getText());
            preview.setText(text.getText());
            preview2.setText(text.getText());
        }
    };
    text.addCaretListener(caretUpdateText);
    text.setPreferredSize(new Dimension(this.getWidth() - 283, 30));
    textPanel.add(textLabel);
    textPanel.add(text);
    nameAndTextPanel.setLayout(new BoxLayout(nameAndTextPanel, BoxLayout.PAGE_AXIS));
    nameAndTextPanel.add(namePanel);
    nameAndTextPanel.add(textPanel);

    JPanel policePanel = new JPanel();
    JLabel policeLabel = new JLabel("Police : ");
    police.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            @SuppressWarnings("unchecked")
            JComboBox<String> combo = (JComboBox<String>) e.getSource();
            fontStyle = (String) combo.getSelectedItem();
            preview.setFont(new Font(fontStyle, Font.PLAIN, fontSize));
            preview2.setFont(new Font(fontStyle, Font.PLAIN, fontSize));
            bs.set("police", fontStyle);
        }

    });
    police.setPreferredSize(new Dimension(105, 30));
    GraphicsEnvironment e = GraphicsEnvironment.getLocalGraphicsEnvironment();
    Font[] fonts = e.getAllFonts();
    for (Font f : fonts) {
        police.addItem(f.getName());
    }
    police.setSelectedItem("Arial");
    policePanel.add(policeLabel);
    policePanel.add(police);

    JPanel sizePanel = new JPanel();
    size.setPreferredSize(new Dimension(60, 25));
    JLabel sizeLabel = new JLabel("Taille : ");
    sizePanel.add(sizeLabel);
    sizePanel.add(size);
    JButton colorButton = new JButton("Couleur");
    colorButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            colorFrame.setModal(false);
            JButton finish = new JButton("Terminer");
            finish.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent arg0) {
                    colorFrame.dispose();
                }

            });
            colorFrame.setLayout(new BorderLayout());
            colorFrame.add(color, BorderLayout.CENTER);
            colorFrame.add(finish, BorderLayout.SOUTH);
            colorFrame.pack();
            colorFrame.setLocation(SwingUtilities.windowForComponent(imagedButton).getX() + 325,
                    SwingUtilities.windowForComponent(imagedButton).getY() - colorFrame.getHeight() + 40);
            colorFrame.setVisible(true);
        }

    });
    sizePanel.add(colorButton);
    size.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            JSpinner spinner = (JSpinner) e.getSource();
            fontSize = (int) spinner.getValue();
            preview.setFont(new Font(fontStyle, Font.PLAIN, fontSize));
            preview2.setFont(new Font(fontStyle, Font.PLAIN, fontSize));
            bs.set("size", fontSize);
        }
    });

    JPanel policeAndSize = new JPanel();
    policeAndSize.setLayout(new BoxLayout(policeAndSize, BoxLayout.PAGE_AXIS));
    policeAndSize.add(policePanel);
    policeAndSize.add(sizePanel);

    JPanel top = new JPanel();
    top.add(nameAndTextPanel);
    top.add(policeAndSize);
    top.setPreferredSize(new Dimension(395, 20));

    this.add(top);

    JPanel images = new JPanel();
    images.setBorder(BorderFactory.createTitledBorder("Images"));
    images.setLayout(new GridLayout(2, 3));
    images.setPreferredSize(new Dimension(395, this.getHeight() - 320));

    JPanel imaged = new JPanel();
    imaged.setLayout(new BorderLayout());
    imaged.setBorder(BorderFactory.createTitledBorder("Icne interne"));
    imagedButton.setSelected(true);
    imagedButton.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent ev) {
            if (ev.getStateChange() == ItemEvent.SELECTED) {
                bs.set("strings", true);
                preview.setBorderPainted(true);
            } else if (ev.getStateChange() == ItemEvent.DESELECTED) {
                bs.set("strings", false);
                preview.setBorderPainted(false);
            }
        }
    });
    JButton browseInternal = new JButton("Parcourir");
    browseInternal.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            String path = null;
            JFileChooser chooser = new JFileChooser(Editor.lastPath);
            FileNameExtensionFilter filter = new FileNameExtensionFilter("Images", "jpg", "png", "gif", "jpeg",
                    "bmp");
            chooser.setFileFilter(filter);
            chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
            int option = chooser.showOpenDialog(null);
            if (option == JFileChooser.APPROVE_OPTION) {
                path = chooser.getSelectedFile().getAbsolutePath();
                Editor.lastPath = chooser.getSelectedFile().getParent();
                copyImage(new File(path), "internal.png");
                nameInternal.setText(new File(path).getName());
                nameInternal.setPreferredSize(new Dimension(imgBasic.getWidth() - 10, 30));
                preview.setIcon(new ImageIcon(path));
                preview.repaint();
                bs.set("imageInternal", new File(path).getName());
            }
        }

    });
    JPanel northImaged = new JPanel();
    northImaged.setLayout(new BorderLayout());
    northImaged.add(imagedButton, BorderLayout.NORTH);
    northImaged.add(browseInternal, BorderLayout.SOUTH);
    imaged.add(northImaged, BorderLayout.NORTH);
    imaged.add(nameInternal, BorderLayout.CENTER);
    JButton removeInternal = null;
    try {
        removeInternal = new JButton(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("remove.png"))));
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    removeInternal.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            File file = new File(
                    "projects/" + Editor.getProjectName() + "/buttons/" + name.getText() + "/internal.png");
            file.delete();
            nameInternal.setText("");
            bs.set("imageInternal", "");
            preview.setIcon(null);
        }

    });
    imaged.add(removeInternal, BorderLayout.SOUTH);
    images.add(imaged);

    imgBasic.setBorder(BorderFactory.createTitledBorder("Base"));
    JButton browseBasic = new JButton("Parcourir");
    browseBasic.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            String path = null;
            JFileChooser chooser = new JFileChooser(Editor.lastPath);
            FileNameExtensionFilter filter = new FileNameExtensionFilter("Images", "jpg", "png", "gif", "jpeg",
                    "bmp");
            chooser.setFileFilter(filter);
            chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
            int option = chooser.showOpenDialog(null);
            if (option == JFileChooser.APPROVE_OPTION) {
                path = chooser.getSelectedFile().getAbsolutePath();
                Editor.lastPath = chooser.getSelectedFile().getParent();
                copyImage(new File(path), "basic.png");
                nameBasic.setText(new File(path).getName());
                nameBasic.setPreferredSize(new Dimension(imgBasic.getWidth() - 10, 30));
                previewPanel.remove(preview);
                previewPanel.remove(preview2);
                previewPanel.add(preview2);
                color.changePreview(preview2);
                bs.set("imageBasic", new File(path).getName());
                preview2.update();
                previewPanel.repaint();
            }
        }

    });
    imgBasic.setLayout(new BorderLayout());
    imgBasic.add(browseBasic, BorderLayout.NORTH);
    imgBasic.add(nameBasic, BorderLayout.CENTER);
    JButton removeBasic = null;
    try {
        removeBasic = new JButton(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("remove.png"))));
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    removeBasic.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            File file = new File(
                    "projects/" + Editor.getProjectName() + "/buttons/" + name.getText() + "/basic.png");
            file.delete();
            nameBasic.setText("");
            bs.set("imageBasic", "");
            preview2.update();
            previewPanel.repaint();
            if (bs.getString("imageBasic").equals("") && bs.getString("imageEntered").equals("")
                    && bs.getString("imageExited").equals("") && bs.getString("imagePressed").equals("")
                    && bs.getString("imageReleased").equals("")) {
                previewPanel.remove(preview2);
                previewPanel.add(preview);
            }
        }

    });
    imgBasic.add(removeBasic, BorderLayout.SOUTH);
    images.add(imgBasic);

    imgEntered.setBorder(BorderFactory.createTitledBorder("Survol"));
    JButton browseEntered = new JButton("Parcourir");
    browseEntered.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            String path = null;
            JFileChooser chooser = new JFileChooser(Editor.lastPath);
            FileNameExtensionFilter filter = new FileNameExtensionFilter("Images", "jpg", "png", "gif", "jpeg",
                    "bmp");
            chooser.setFileFilter(filter);
            chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
            int option = chooser.showOpenDialog(null);
            if (option == JFileChooser.APPROVE_OPTION) {
                path = chooser.getSelectedFile().getAbsolutePath();
                Editor.lastPath = chooser.getSelectedFile().getParent();
                copyImage(new File(path), "entered.png");
                nameEntered.setText(new File(path).getName());
                nameEntered.setPreferredSize(new Dimension(imgEntered.getWidth() - 10, 30));
                bs.set("imageEntered", new File(path).getName());
                preview2.update();
                previewPanel.repaint();
            }
        }

    });
    imgEntered.setLayout(new BorderLayout());
    imgEntered.add(browseEntered, BorderLayout.NORTH);
    imgEntered.add(nameEntered, BorderLayout.CENTER);
    JButton removeEntered = null;
    try {
        removeEntered = new JButton(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("remove.png"))));
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    removeEntered.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            File file = new File(
                    "projects/" + Editor.getProjectName() + "/buttons/" + name.getText() + "/entered.png");
            file.delete();
            nameEntered.setText("");
            bs.set("imageEntered", "");
            preview2.update();
            previewPanel.repaint();
            if (bs.getString("imageBasic").equals("") && bs.getString("imageEntered").equals("")
                    && bs.getString("imageExited").equals("") && bs.getString("imagePressed").equals("")
                    && bs.getString("imageReleased").equals("")) {
                previewPanel.remove(preview2);
                previewPanel.add(preview);
            }
        }

    });
    imgEntered.add(removeEntered, BorderLayout.SOUTH);
    images.add(imgEntered);

    imgExited.setBorder(BorderFactory.createTitledBorder("Sortie"));
    JButton browseExited = new JButton("Parcourir");
    browseExited.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            String path = null;
            JFileChooser chooser = new JFileChooser(Editor.lastPath);
            FileNameExtensionFilter filter = new FileNameExtensionFilter("Images", "jpg", "png", "gif", "jpeg",
                    "bmp");
            chooser.setFileFilter(filter);
            chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
            int option = chooser.showOpenDialog(null);
            if (option == JFileChooser.APPROVE_OPTION) {
                path = chooser.getSelectedFile().getAbsolutePath();
                Editor.lastPath = chooser.getSelectedFile().getParent();
                copyImage(new File(path), "exited.png");
                nameExited.setText(new File(path).getName());
                nameExited.setPreferredSize(new Dimension(imgExited.getWidth() - 10, 30));
                bs.set("imageExited", new File(path).getName());
                preview2.update();
                previewPanel.repaint();
            }
        }

    });
    imgExited.setLayout(new BorderLayout());
    imgExited.add(browseExited, BorderLayout.NORTH);
    imgExited.add(nameExited, BorderLayout.CENTER);
    JButton removeExited = null;
    try {
        removeExited = new JButton(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("remove.png"))));
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    removeExited.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            File file = new File(
                    "projects/" + Editor.getProjectName() + "/buttons/" + name.getText() + "/exited.png");
            file.delete();
            nameExited.setText("");
            bs.set("imageExited", "");
            preview2.update();
            previewPanel.repaint();
            if (bs.getString("imageBasic").equals("") && bs.getString("imageEntered").equals("")
                    && bs.getString("imageExited").equals("") && bs.getString("imagePressed").equals("")
                    && bs.getString("imageReleased").equals("")) {
                previewPanel.remove(preview2);
                previewPanel.add(preview);
            }
        }

    });
    imgExited.add(removeExited, BorderLayout.SOUTH);
    images.add(imgExited);

    imgPressed.setBorder(BorderFactory.createTitledBorder("Clic"));
    JButton browsePressed = new JButton("Parcourir");
    browsePressed.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            String path = null;
            JFileChooser chooser = new JFileChooser(Editor.lastPath);
            FileNameExtensionFilter filter = new FileNameExtensionFilter("Images", "jpg", "png", "gif", "jpeg",
                    "bmp");
            chooser.setFileFilter(filter);
            chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
            int option = chooser.showOpenDialog(null);
            if (option == JFileChooser.APPROVE_OPTION) {
                path = chooser.getSelectedFile().getAbsolutePath();
                Editor.lastPath = chooser.getSelectedFile().getParent();
                copyImage(new File(path), "pressed.png");
                namePressed.setText(new File(path).getName());
                namePressed.setPreferredSize(new Dimension(imgPressed.getWidth() - 10, 30));
                bs.set("imagePressed", new File(path).getName());
                preview2.update();
                previewPanel.repaint();
            }
        }

    });
    imgPressed.setLayout(new BorderLayout());
    imgPressed.add(browsePressed, BorderLayout.NORTH);
    imgPressed.add(namePressed, BorderLayout.CENTER);
    JButton removePressed = null;
    try {
        removePressed = new JButton(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("remove.png"))));
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    removePressed.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            File file = new File(
                    "projects/" + Editor.getProjectName() + "/buttons/" + name.getText() + "/pressed.png");
            file.delete();
            namePressed.setText("");
            bs.set("imagePressed", "");
            preview2.update();
            previewPanel.repaint();
            if (bs.getString("imageBasic").equals("") && bs.getString("imageEntered").equals("")
                    && bs.getString("imageExited").equals("") && bs.getString("imagePressed").equals("")
                    && bs.getString("imageReleased").equals("")) {
                previewPanel.remove(preview2);
                previewPanel.add(preview);
            }
        }

    });
    imgPressed.add(removePressed, BorderLayout.SOUTH);
    images.add(imgPressed);

    imgReleased.setBorder(BorderFactory.createTitledBorder("Relachement"));
    JButton browseReleased = new JButton("Parcourir");
    browseReleased.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            String path = null;
            JFileChooser chooser = new JFileChooser(Editor.lastPath);
            FileNameExtensionFilter filter = new FileNameExtensionFilter("Images", "jpg", "png", "gif", "jpeg",
                    "bmp");
            chooser.setFileFilter(filter);
            chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
            int option = chooser.showOpenDialog(null);
            if (option == JFileChooser.APPROVE_OPTION) {
                path = chooser.getSelectedFile().getAbsolutePath();
                Editor.lastPath = chooser.getSelectedFile().getParent();
                copyImage(new File(path), "released.png");
                nameReleased.setText(new File(path).getName());
                nameReleased.setPreferredSize(new Dimension(imgReleased.getWidth() - 10, 30));
                bs.set("imageReleased", new File(path).getName());
                preview2.update();
                previewPanel.repaint();
            }
        }

    });
    imgReleased.setLayout(new BorderLayout());
    imgReleased.add(browseReleased, BorderLayout.NORTH);
    imgReleased.add(nameReleased, BorderLayout.CENTER);
    JButton removeReleased = null;
    try {
        removeReleased = new JButton(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("remove.png"))));
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    removeReleased.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            File file = new File(
                    "projects/" + Editor.getProjectName() + "/buttons/" + name.getText() + "/released.png");
            file.delete();
            nameReleased.setText("");
            bs.set("imageReleased", "");
            preview2.update();
            previewPanel.repaint();
            if (bs.getString("imageBasic").equals("") && bs.getString("imageEntered").equals("")
                    && bs.getString("imageExited").equals("") && bs.getString("imagePressed").equals("")
                    && bs.getString("imageReleased").equals("")) {
                previewPanel.remove(preview2);
                previewPanel.add(preview);
            }
        }

    });
    imgReleased.add(removeReleased, BorderLayout.SOUTH);
    images.add(imgReleased);

    this.add(images);

    JPanel action = new JPanel();
    action.setPreferredSize(new Dimension(395, -20));
    JLabel labelAction = new JLabel("Action : ");
    action.add(labelAction);
    actionList.removeAllItems();
    actionList.addItem("Aucune");
    for (String s : Actions.getActions()) {
        actionList.addItem(s);
    }
    actionList.setPreferredSize(new Dimension(this.getWidth() - 100, 30));
    actionList.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            @SuppressWarnings("unchecked")
            JComboBox<String> combo = (JComboBox<String>) event.getSource();
            bs.set("action", combo.getSelectedItem());
        }

    });
    action.add(actionList);
    this.add(action);

    JScrollPane previewScroll = new JScrollPane(previewPanel);
    previewScroll.getVerticalScrollBar().setUnitIncrement(Editor.SCROLL_SPEED);
    previewPanel.setBorder(BorderFactory.createTitledBorder("Aperu"));
    previewPanel.add(preview);
    previewScroll.setPreferredSize(new Dimension(395, 40));
    previewScroll.setBorder(null);

    this.add(previewScroll);
}

From source file:org.ut.biolab.medsavant.client.query.view.NumberSearchConditionEditorView.java

@Override
public void loadViewFromSearchConditionParameters(String encoding) throws ConditionRestorationException {

    double[] selectedValues;
    if (encoding == null) {
        selectedValues = null;/*from   www .  j  a v a 2 s  .c o  m*/
    } else {
        selectedValues = NumericConditionEncoder.unencodeConditions(encoding);
    }

    final double[] extremeValues = generator.getExtremeNumericValues();
    this.removeAll();

    if (extremeValues == null || (extremeValues[0] == 0 && extremeValues[1] == 0)) {
        JPanel p = new JPanel();
        p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
        p.add(Box.createHorizontalGlue());
        p.add(new JLabel("<html>All values are blank for this condition.</html>"));
        p.add(Box.createHorizontalGlue());
        this.add(p);
        return;
    }

    setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

    JPanel p = ViewUtil.getClearPanel();
    ViewUtil.applyVerticalBoxLayout(p);

    JPanel labelPanel = ViewUtil.getClearPanel();
    ViewUtil.applyHorizontalBoxLayout(labelPanel);
    labelPanel.add(Box.createHorizontalGlue());
    labelPanel.add(new JLabel("Filtering variants where " + item.getName() + ": "));
    labelPanel.add(Box.createHorizontalGlue());
    ButtonGroup group = new ButtonGroup();
    //JRadioButton isButton = new JRadioButton("is within the following range:");
    //JRadioButton nullButton = new JRadioButton("is missing");
    //group.add(isButton);
    //group.add(nullButton);

    final JCheckBox nullButton = new JCheckBox("include missing values");

    JPanel bp = ViewUtil.getClearPanel();
    ViewUtil.applyHorizontalBoxLayout(bp);
    p.add(labelPanel);
    p.add(bp);
    add(p);
    final DecimalRangeSlider slider = new DecimalRangeSlider();

    slider.setMajorTickSpacing(5);
    slider.setMinorTickSpacing(1);

    final JTextField fromBox = new JTextField();
    final JTextField toBox = new JTextField();

    nullButton.setSelected(NumericConditionEncoder.encodesNull(encoding));

    nullButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            encodeValue(ViewUtil.parseDoubleFromFormattedString(fromBox.getText()),
                    ViewUtil.parseDoubleFromFormattedString(toBox.getText()), extremeValues[0],
                    extremeValues[1], nullButton.isSelected());
        }
    });

    fromBox.setMaximumSize(new Dimension(10000, 24));
    toBox.setMaximumSize(new Dimension(10000, 24));
    fromBox.setPreferredSize(new Dimension(FROM_TO_WIDTH, 24));
    toBox.setPreferredSize(new Dimension(FROM_TO_WIDTH, 24));
    fromBox.setMinimumSize(new Dimension(FROM_TO_WIDTH, 24));
    toBox.setMinimumSize(new Dimension(FROM_TO_WIDTH, 24));
    fromBox.setHorizontalAlignment(JTextField.RIGHT);
    toBox.setHorizontalAlignment(JTextField.RIGHT);

    final JLabel fromLabel = new JLabel();
    final JLabel toLabel = new JLabel();

    ViewUtil.makeMini(fromLabel);
    ViewUtil.makeMini(toLabel);

    JPanel fromToContainer = ViewUtil.getClearPanel();
    ViewUtil.applyHorizontalBoxLayout(fromToContainer);
    fromToContainer.add(Box.createHorizontalGlue());
    fromToContainer.add(fromBox);
    fromToContainer.add(new JLabel(" - "));
    fromToContainer.add(toBox);
    fromToContainer.add(Box.createHorizontalGlue());

    JPanel minMaxContainer = ViewUtil.getClearPanel();
    minMaxContainer.setLayout(new BoxLayout(minMaxContainer, BoxLayout.X_AXIS));

    JPanel sliderContainer = ViewUtil.getClearPanel();
    sliderContainer.setLayout(new BoxLayout(sliderContainer, BoxLayout.Y_AXIS));
    sliderContainer.add(slider);

    JPanel nullValueContainer = ViewUtil.getClearPanel();
    ViewUtil.applyHorizontalBoxLayout(nullValueContainer);
    nullValueContainer.add(Box.createHorizontalGlue());
    nullValueContainer.add(nullButton);
    nullButton.setBackground(nullValueContainer.getBackground()); //fixes a windows issue.
    nullValueContainer.add(Box.createHorizontalGlue());

    JPanel labelContainer = ViewUtil.getClearPanel();
    labelContainer.setLayout(new BoxLayout(labelContainer, BoxLayout.X_AXIS));
    labelContainer.add(fromLabel);
    labelContainer.add(Box.createHorizontalGlue());
    labelContainer.add(toLabel);
    sliderContainer.add(labelContainer);
    minMaxContainer.add(Box.createHorizontalGlue());
    minMaxContainer.add(sliderContainer);
    minMaxContainer.add(Box.createHorizontalGlue());

    add(fromToContainer);
    add(minMaxContainer);
    add(nullValueContainer);
    add(Box.createVerticalBox());

    slider.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent e) {
            if (slider.isEnabled()) {
                fromBox.setText(ViewUtil.numToString(slider.getLow()));
                toBox.setText(ViewUtil.numToString(slider.getHigh()));
                encodeValue(ViewUtil.parseDoubleFromFormattedString(fromBox.getText()),
                        ViewUtil.parseDoubleFromFormattedString(toBox.getText()), extremeValues[0],
                        extremeValues[1], nullButton.isSelected());
            }
        }
    });

    final KeyListener keyListener = new KeyAdapter() {
        @Override
        public void keyReleased(KeyEvent e) {
            int key = e.getKeyCode();
            if (key == KeyEvent.VK_ENTER) {
                Range selectedRage = new Range(getNumber(fromBox.getText()), getNumber(toBox.getText()));
                setSelectedValues(slider, fromBox, toBox, selectedRage);
            }
        }

        private double getNumber(String s) {
            try {
                return Double.parseDouble(s.replaceAll(",", ""));
            } catch (NumberFormatException ignored) {
                return 0;
            }
        }
    };

    CaretListener caretListener = new CaretListener() {
        @Override
        public void caretUpdate(CaretEvent ce) {
            if (!isAdjustingSlider) {
                try {
                    encodeValue(ViewUtil.parseDoubleFromFormattedString(fromBox.getText()),
                            ViewUtil.parseDoubleFromFormattedString(toBox.getText()), extremeValues[0],
                            extremeValues[1], nullButton.isSelected());
                } catch (Exception e) {
                }
            }
        }
    };

    fromBox.addKeyListener(keyListener);

    toBox.addKeyListener(keyListener);

    fromBox.addCaretListener(caretListener);

    toBox.addCaretListener(caretListener);

    slider.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            isAdjustingSlider = true;
            fromBox.setText(ViewUtil.numToString(slider.getLow()));
            toBox.setText(ViewUtil.numToString(slider.getHigh()));
            isAdjustingSlider = false;
        }
    });

    JPanel bottomContainer = new JPanel();

    bottomContainer.setLayout(new BoxLayout(bottomContainer, BoxLayout.X_AXIS));

    bottomContainer.add(Box.createHorizontalGlue());

    add(bottomContainer);

    setExtremeValues(slider, fromLabel, toLabel, fromBox, toBox, 0,
            new Range(extremeValues[0], extremeValues[1]));

    if (encoding != null) {
        double[] d = NumericConditionEncoder.unencodeConditions(encoding);
        setSelectedValues(slider, fromBox, toBox, new Range(d[0], d[1]));
    }
}