List of usage examples for javax.swing JTextField setMaximumSize
@BeanProperty(description = "The maximum size of the component.") public void setMaximumSize(Dimension maximumSize)
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 ww w.j a v a2s. c om } 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])); } }
From source file:savant.snp.SNPFinderPlugin.java
private void setupGUI(JPanel panel) { // add a toolbar JToolBar tb = new JToolBar(); tb.setName("SNP Finder Toolbar"); // add an ON/OFF checkbox JLabel lab_on = new JLabel("On/Off: "); JCheckBox cb_on = new JCheckBox(); cb_on.setSelected(isSNPFinderOn);/*from w ww . j a v a 2 s . c o m*/ // what to do when a user clicks the checkbox cb_on.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // switch the SNP finder on/off setIsOn(!isSNPFinderOn); addMessage("Turning SNP finder " + (isSNPFinderOn ? "on" : "off")); } }); // add a Bookmarking ON/OFF checkbox JLabel lab_bm = new JLabel("Add Bookmarks: "); JCheckBox cb_bm = new JCheckBox(); cb_bm.setSelected(addBookmarks); // what to do when a user clicks the checkbox cb_bm.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // switch the SNP finder on/off setBookmarking(!addBookmarks); addMessage("Turning Bookmarking " + (addBookmarks ? "on" : "off")); } }); JLabel lab_sp = new JLabel("Heterozygosity: "); //add snp prior textfield final JTextField snpPriorField = new JTextField(String.valueOf(snpPrior), 4); snpPriorField.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { setSNPPrior(Double.valueOf(snpPriorField.getText())); } catch (NumberFormatException ex) { snpPriorField.setText(String.valueOf(snpPrior)); } } }); int tfwidth = 35; int tfheight = 22; snpPriorField.setPreferredSize(new Dimension(tfwidth, tfheight)); snpPriorField.setMaximumSize(new Dimension(tfwidth, tfheight)); snpPriorField.setMinimumSize(new Dimension(tfwidth, tfheight)); // add a sensitivity slider JLabel lab_confidence = new JLabel("Confidence: "); final JSlider sens_slider = new JSlider(0, 50); sens_slider.setValue(confidence); final JLabel lab_confidence_status = new JLabel("" + sens_slider.getValue()); // what to do when a user slides the slider sens_slider.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { // set the snp finder's sensitivity lab_confidence_status.setText("" + sens_slider.getValue()); setSensitivity(sens_slider.getValue()); } }); // don't report the new setting until the user stops sliding sens_slider.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { addMessage("Changed confidence to " + confidence); } }); // add a transparency slider JLabel lab_trans = new JLabel("Transparency: "); final JSlider trans_slider = new JSlider(0, 100); trans_slider.setValue(transparency); final JLabel lab_transparency_status = new JLabel("" + trans_slider.getValue()); // what to do when a user slides the slider trans_slider.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { // set the snp finder's transparency lab_transparency_status.setText("" + trans_slider.getValue()); setTransparency(trans_slider.getValue()); } }); // don't report the new setting until the user stops sliding trans_slider.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { addMessage("Changed transparency to " + transparency); } }); // add the components to the GUI panel.setLayout(new BorderLayout()); tb.add(lab_on); tb.add(cb_on); tb.add(lab_bm); tb.add(cb_bm); tb.add(new JToolBar.Separator()); tb.add(lab_sp); tb.add(snpPriorField); tb.add(new JToolBar.Separator()); tb.add(lab_confidence); tb.add(sens_slider); tb.add(lab_confidence_status); tb.add(new JToolBar.Separator()); tb.add(lab_trans); tb.add(trans_slider); tb.add(lab_transparency_status); panel.add(tb, BorderLayout.NORTH); // add a text area to the GUI info = new JTextArea(); JScrollPane scrollPane = new JScrollPane(info); panel.add(scrollPane, BorderLayout.CENTER); }