List of usage examples for javax.swing JTextField setText
@BeanProperty(bound = false, description = "the text of this component") public void setText(String t)
TextComponent
to the specified text. From source file:pipeline.parameter_cell_views.FloatSlider.java
private void updateTextValue(JTextField f, float v) { f.setText("" + format(v)); }
From source file:pipeline.parameter_cell_views.IntRangeSlider.java
private void updateTextValue(JTextField f, int v) { f.setText("" + nf.format(v)); }
From source file:pipeline.parameter_cell_views.IntSlider.java
private void updateTextValue(JTextField f, int v) { f.setText("" + getNumberFormatter().format(v)); }
From source file:pl.otros.logview.gui.LogViewMainFrame.java
private void initToolbar() { toolBar = new JToolBar(); final JComboBox searchMode = new JComboBox( new String[] { "String contains search: ", "Regex search: ", "Query search: " }); final SearchAction searchActionForward = new SearchAction(otrosApplication, SearchDirection.FORWARD); final SearchAction searchActionBackward = new SearchAction(otrosApplication, SearchDirection.REVERSE); searchFieldCbxModel = new DefaultComboBoxModel(); searchField = new JXComboBox(searchFieldCbxModel); searchField.setEditable(true);//from w w w. ja v a 2 s. c o m AutoCompleteDecorator.decorate(searchField); searchField.setMinimumSize(new Dimension(150, 10)); searchField.setPreferredSize(new Dimension(250, 10)); searchField.setToolTipText( "<HTML>Enter text to search.<BR/>" + "Enter - search next,<BR/>Alt+Enter search previous,<BR/>" + "Ctrl+Enter - mark all found</HTML>"); final DelayedSwingInvoke delayedSearchResultUpdate = new DelayedSwingInvoke() { @Override protected void performActionHook() { JTextComponent editorComponent = (JTextComponent) searchField.getEditor().getEditorComponent(); int stringEnd = editorComponent.getSelectionStart(); if (stringEnd < 0) { stringEnd = editorComponent.getText().length(); } try { String selectedText = editorComponent.getText(0, stringEnd); if (StringUtils.isBlank(selectedText)) { return; } OtrosJTextWithRulerScrollPane<JTextPane> logDetailWithRulerScrollPane = otrosApplication .getSelectedLogViewPanel().getLogDetailWithRulerScrollPane(); MessageUpdateUtils.highlightSearchResult(logDetailWithRulerScrollPane, otrosApplication.getAllPluginables().getMessageColorizers()); RulerBarHelper.scrollToFirstMarker(logDetailWithRulerScrollPane); } catch (BadLocationException e) { LOGGER.log(Level.SEVERE, "Can't update search highlight", e); } } }; JTextComponent searchFieldTextComponent = (JTextComponent) searchField.getEditor().getEditorComponent(); searchFieldTextComponent.getDocument().addDocumentListener(new DocumentInsertUpdateHandler() { @Override protected void documentChanged(DocumentEvent e) { delayedSearchResultUpdate.performAction(); } }); final MarkAllFoundAction markAllFoundAction = new MarkAllFoundAction(otrosApplication); final SearchModeValidatorDocumentListener searchValidatorDocumentListener = new SearchModeValidatorDocumentListener( (JTextField) searchField.getEditor().getEditorComponent(), observer, SearchMode.STRING_CONTAINS); SearchMode searchModeFromConfig = configuration.get(SearchMode.class, "gui.searchMode", SearchMode.STRING_CONTAINS); final String lastSearchString; int selectedSearchMode = 0; if (searchModeFromConfig.equals(SearchMode.STRING_CONTAINS)) { selectedSearchMode = 0; lastSearchString = configuration.getString(ConfKeys.SEARCH_LAST_STRING, ""); } else if (searchModeFromConfig.equals(SearchMode.REGEX)) { selectedSearchMode = 1; lastSearchString = configuration.getString(ConfKeys.SEARCH_LAST_REGEX, ""); } else if (searchModeFromConfig.equals(SearchMode.QUERY)) { selectedSearchMode = 2; lastSearchString = configuration.getString(ConfKeys.SEARCH_LAST_QUERY, ""); } else { LOGGER.warning("Unknown search mode " + searchModeFromConfig); lastSearchString = ""; } Component editorComponent = searchField.getEditor().getEditorComponent(); if (editorComponent instanceof JTextField) { final JTextField sfTf = (JTextField) editorComponent; sfTf.getDocument().addDocumentListener(searchValidatorDocumentListener); sfTf.getDocument().addDocumentListener(new DocumentInsertUpdateHandler() { @Override protected void documentChanged(DocumentEvent e) { try { int length = e.getDocument().getLength(); if (length > 0) { searchResultColorizer.setSearchString(e.getDocument().getText(0, length)); } } catch (BadLocationException e1) { LOGGER.log(Level.SEVERE, "Error: ", e1); } } }); sfTf.addKeyListener(new SearchFieldKeyListener(searchActionForward, sfTf)); sfTf.setText(lastSearchString); } searchMode.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { SearchMode mode = null; boolean validationEnabled = false; String confKey = null; String lastSearch = ((JTextField) searchField.getEditor().getEditorComponent()).getText(); if (searchMode.getSelectedIndex() == 0) { mode = SearchMode.STRING_CONTAINS; searchValidatorDocumentListener.setSearchMode(mode); validationEnabled = false; searchMode.setToolTipText("Checking if log message contains string (case is ignored)"); confKey = ConfKeys.SEARCH_LAST_STRING; } else if (searchMode.getSelectedIndex() == 1) { mode = SearchMode.REGEX; validationEnabled = true; searchMode .setToolTipText("Checking if log message matches regular expression (case is ignored)"); confKey = ConfKeys.SEARCH_LAST_REGEX; } else if (searchMode.getSelectedIndex() == 2) { mode = SearchMode.QUERY; validationEnabled = true; String querySearchTooltip = "<HTML>" + // "Advance search using SQL-like quries (i.e. level>=warning && msg~=failed && thread==t1)<BR/>" + // "Valid operator for query search is ==, ~=, !=, LIKE, EXISTS, <, <=, >, >=, &&, ||, ! <BR/>" + // "See wiki for more info<BR/>" + // "</HTML>"; searchMode.setToolTipText(querySearchTooltip); confKey = ConfKeys.SEARCH_LAST_QUERY; } searchValidatorDocumentListener.setSearchMode(mode); searchValidatorDocumentListener.setEnable(validationEnabled); searchActionForward.setSearchMode(mode); searchActionBackward.setSearchMode(mode); markAllFoundAction.setSearchMode(mode); configuration.setProperty("gui.searchMode", mode); searchResultColorizer.setSearchMode(mode); List<Object> list = configuration.getList(confKey); searchFieldCbxModel.removeAllElements(); for (Object o : list) { searchFieldCbxModel.addElement(o); } searchField.setSelectedItem(lastSearch); } }); searchMode.setSelectedIndex(selectedSearchMode); final JCheckBox markFound = new JCheckBox("Mark search result"); markFound.setMnemonic(KeyEvent.VK_M); searchField.addKeyListener(markAllFoundAction); configuration.addConfigurationListener(markAllFoundAction); JButton markAllFoundButton = new JButton(markAllFoundAction); final JComboBox markColor = new JComboBox(MarkerColors.values()); markFound.setSelected(configuration.getBoolean("gui.markFound", true)); markFound.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { boolean selected = markFound.isSelected(); searchActionForward.setMarkFound(selected); searchActionBackward.setMarkFound(selected); configuration.setProperty("gui.markFound", markFound.isSelected()); } }); markColor.setRenderer(new MarkerColorsComboBoxRenderer()); // markColor.addActionListener(new ActionListener() { // // @Override // public void actionPerformed(ActionEvent e) { // MarkerColors markerColors = (MarkerColors) markColor.getSelectedItem(); // searchActionForward.setMarkerColors(markerColors); // searchActionBackward.setMarkerColors(markerColors); // markAllFoundAction.setMarkerColors(markerColors); // configuration.setProperty("gui.markColor", markColor.getSelectedItem()); // otrosApplication.setSelectedMarkColors(markerColors); // } // }); markColor.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { MarkerColors markerColors = (MarkerColors) markColor.getSelectedItem(); searchActionForward.setMarkerColors(markerColors); searchActionBackward.setMarkerColors(markerColors); markAllFoundAction.setMarkerColors(markerColors); configuration.setProperty("gui.markColor", markColor.getSelectedItem()); otrosApplication.setSelectedMarkColors(markerColors); } }); markColor.getModel() .setSelectedItem(configuration.get(MarkerColors.class, "gui.markColor", MarkerColors.Aqua)); buttonSearch = new JButton(searchActionForward); buttonSearch.setMnemonic(KeyEvent.VK_N); JButton buttonSearchPrev = new JButton(searchActionBackward); buttonSearchPrev.setMnemonic(KeyEvent.VK_P); enableDisableComponetsForTabs.addComponet(buttonSearch); enableDisableComponetsForTabs.addComponet(buttonSearchPrev); enableDisableComponetsForTabs.addComponet(searchField); enableDisableComponetsForTabs.addComponet(markFound); enableDisableComponetsForTabs.addComponet(markAllFoundButton); enableDisableComponetsForTabs.addComponet(searchMode); enableDisableComponetsForTabs.addComponet(markColor); toolBar.add(searchMode); toolBar.add(searchField); toolBar.add(buttonSearch); toolBar.add(buttonSearchPrev); toolBar.add(markFound); toolBar.add(markAllFoundButton); toolBar.add(markColor); JButton nextMarked = new JButton(new JumpToMarkedAction(otrosApplication, Direction.FORWARD)); nextMarked.setToolTipText(nextMarked.getText()); nextMarked.setText(""); nextMarked.setMnemonic(KeyEvent.VK_E); enableDisableComponetsForTabs.addComponet(nextMarked); toolBar.add(nextMarked); JButton prevMarked = new JButton(new JumpToMarkedAction(otrosApplication, Direction.BACKWARD)); prevMarked.setToolTipText(prevMarked.getText()); prevMarked.setText(""); prevMarked.setMnemonic(KeyEvent.VK_R); enableDisableComponetsForTabs.addComponet(prevMarked); toolBar.add(prevMarked); enableDisableComponetsForTabs.addComponet(toolBar.add(new SearchByLevel(otrosApplication, 1, Level.INFO))); enableDisableComponetsForTabs .addComponet(toolBar.add(new SearchByLevel(otrosApplication, 1, Level.WARNING))); enableDisableComponetsForTabs .addComponet(toolBar.add(new SearchByLevel(otrosApplication, 1, Level.SEVERE))); enableDisableComponetsForTabs.addComponet(toolBar.add(new SearchByLevel(otrosApplication, -1, Level.INFO))); enableDisableComponetsForTabs .addComponet(toolBar.add(new SearchByLevel(otrosApplication, -1, Level.WARNING))); enableDisableComponetsForTabs .addComponet(toolBar.add(new SearchByLevel(otrosApplication, -1, Level.SEVERE))); }
From source file:qic.ui.ManualPanel.java
@SuppressWarnings("serial") public ManualPanel(Main main) { super(new BorderLayout(5, 5)); table.setDoubleBuffered(true);//from w ww.j a v a 2s .c o m JTextField searchTf = new JTextField(100); JButton runBtn = new JButton("Run"); runBtn.setPreferredSize(new Dimension(200, 10)); JLabel invalidTermsLblLbl = new JLabel(); invalidTermsLblLbl.setFont(invalidTermsLblLbl.getFont().deriveFont(Font.BOLD)); JLabel invalidTermsLbl = new JLabel(); invalidTermsLbl.setForeground(Color.RED); JPanel northPanel = new JPanel(); northPanel.setLayout(new BoxLayout(northPanel, BoxLayout.X_AXIS)); JLabel searchLbl = new JLabel(" Search: "); searchLbl.setFont(searchLbl.getFont().deriveFont(Font.BOLD)); northPanel.add(searchLbl); northPanel.add(searchTf); northPanel.add(invalidTermsLblLbl); northPanel.add(invalidTermsLbl); northPanel.add(runBtn); this.add(northPanel, BorderLayout.NORTH); List<String> searchList = Util.loadSearchList(MANUAL_TXT_FILENAME); searchList.stream().forEach(searchJListModel::addElement); searchJList.setModel(searchJListModel); searchJList.addListSelectionListener(e -> { if (e.getValueIsAdjusting()) { searchTf.setText(trimToEmpty(searchJList.getSelectedValue())); } }); searchJList.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { if (evt.getClickCount() == 2) { int index = searchJList.locationToIndex(evt.getPoint()); if (index != -1) { String search = trimToEmpty(searchJListModel.getElementAt(index)); searchTf.setText(search); runBtn.doClick(); } } } }); searchJList.getInputMap().put(KeyStroke.getKeyStroke("DELETE"), "doSomething"); searchJList.getActionMap().put("doSomething", new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { int selectedIndex = searchJList.getSelectedIndex(); if (selectedIndex != -1) { searchJListModel.remove(selectedIndex); } } }); ActionListener runCommand = e -> { String tfText = searchTf.getText().trim(); if (!tfText.isEmpty()) { Worker<Command> worker = new Worker<Command>(() -> { runBtn.setEnabled(false); Command result = null; try { result = runQuery(main, tfText); } catch (Exception ex) { runBtn.setEnabled(true); SwingUtil.showError(ex); } return result; }, command -> { if (command != null) { if (command.invalidSearchTerms.isEmpty()) { addDataToTable(command); saveSearchToList(tfText); invalidTermsLbl.setText(""); invalidTermsLblLbl.setText(""); if (getBooleanProperty(MANUAL_AUTO_VERIFY, false)) { long sleep = Config.getLongProperty(Config.MANUAL_AUTO_VERIFY_SLEEP, 5000); table.runAutoVerify(sleep); } } else { String invalidTermsStr = command.invalidSearchTerms.stream().collect(joining(", ")); invalidTermsLbl.setText(invalidTermsStr + " "); invalidTermsLblLbl.setText(" Invalid: "); } } runBtn.setEnabled(true); }); worker.execute(); } }; searchTf.addActionListener(runCommand); runBtn.addActionListener(runCommand); splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, new JScrollPane(table), new JScrollPane(searchJList)); this.add(splitPane, BorderLayout.CENTER); }
From source file:qic.ui.QicFrame.java
public QicFrame(Main main, String query) { super("QIC Search - Simple GUI"); setLayout(new BorderLayout(5, 5)); RSyntaxTextArea textArea = new RSyntaxTextArea(20, 60); textArea.setText("Enter a command in the textfield then press Enter.."); textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JSON); textArea.setCodeFoldingEnabled(true); RTextScrollPane sp = new RTextScrollPane(textArea); JTextField searchTf = new JTextField(100); JButton runBtn = new JButton("Run"); JPanel northPanel = new JPanel(); northPanel.setLayout(new BoxLayout(northPanel, BoxLayout.X_AXIS)); northPanel.add(searchTf);/*from www. ja v a2s . co m*/ northPanel.add(runBtn); getContentPane().add(northPanel, BorderLayout.NORTH); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); setSize(screenSize.width - 50, screenSize.height - 50); setLocationRelativeTo(null); searchTf.setText("search bo tmpsc "); if (query != null) { searchTf.setText(query); } JTable table = new JTable(); table.setDefaultRenderer(List.class, new MultiLineTableCellRenderer()); JTabbedPane tabbedPane = new JTabbedPane(); tabbedPane.addTab("Table", new JScrollPane(table)); tabbedPane.addTab("JSON", new JScrollPane(sp)); BeanPropertyTableModel<SearchResultItem> model = new BeanPropertyTableModel<>(SearchResultItem.class); model.setOrderedProperties(asList("id", "buyout", "item", "seller", "reqs", "mods", "q", "APS", "PDPS", "EDPS", "DPS", "ele", "phys", "ar", "ev", "ES", "blk", "crit", "lvl")); table.setModel(model); setColumnWidths(table.getColumnModel(), asList(1, 15, 280, 230, 50, 420)); getContentPane().add(tabbedPane, BorderLayout.CENTER); ActionListener runCommand = e -> { String tfText = searchTf.getText(); Worker<Command> pathNotesWorker = new Worker<Command>(() -> runQuery(main, tfText), command -> { String json = command.toJson(); textArea.setText(json); model.setData(command.itemResults); }, ex -> { String stackTrace = ExceptionUtils.getStackTrace(ex); textArea.setText(stackTrace); showError(ex); }); pathNotesWorker.execute(); }; searchTf.addActionListener(runCommand); runBtn.addActionListener(runCommand); table.getSelectionModel().addListSelectionListener(e -> { if (e.getValueIsAdjusting()) { int selectedRow = table.getSelectedRow(); if (selectedRow > -1) { SearchResultItem searchResultItem = model.getData().get(selectedRow); SwingUtil.copyToClipboard(searchResultItem.wtb()); } } }); setDefaultCloseOperation(EXIT_ON_CLOSE); setVisible(true); }
From source file:qrcode.JavaQR.java
@Override public void run() { setLayout(new BorderLayout()); JPanel topPanel = new JPanel(); JPanel centerPanel = new JPanel(); JPanel bottomPanel = new JPanel(); topPanel.setLayout(new GridLayout(0, 1)); topPanel.setBorder(BorderFactory.createTitledBorder("Input Data")); JPanel rowTopPanel = new JPanel(); rowTopPanel.setLayout(new GridLayout(0, 2)); JLabel accKey = new JLabel("Access Key"); JTextField accField = new JTextField(5); accField.setEditable(false);/* ww w . j ava2 s. co m*/ accField.setText(Data.accessKey); JLabel regNo = new JLabel("Registration Number"); JTextField regField = new JTextField(5); regField.setEditable(false); regField.setText(Data.registrationNumber); JLabel licNo = new JLabel("License Number"); JFormattedTextField licField = new JFormattedTextField(); licField.setEditable(false); licField.setText(Data.licenseNumber); rowTopPanel.add(accKey); rowTopPanel.add(accField); rowTopPanel.add(regNo); rowTopPanel.add(regField); rowTopPanel.add(licNo); rowTopPanel.add(licField); topPanel.add(rowTopPanel); centerPanel.setLayout(new GridLayout(0, 1)); centerPanel.setBorder(BorderFactory.createTitledBorder("QR Code")); JPanel rowCenPanel = new JPanel(); rowCenPanel.setLayout(new FlowLayout(FlowLayout.CENTER)); JButton genBtn = new JButton("Download QR Code"); JButton homeBtn = new JButton("Back to Start"); String accessKey = accField.getText().toString(); String regKey = regField.getText().toString(); String licKey = licField.getText().toString(); JSONObject jsonObject = new JSONObject(); try { jsonObject.put("accessKey", accessKey); jsonObject.put("registrationNumber", regKey); jsonObject.put("licenseNumber", licKey); } catch (JSONException e1) { e1.printStackTrace(); } QRLogic qrGen = new QRLogic(); BufferedImage image = qrGen.generateQR(jsonObject); centerPanel.add(new JLabel(new ImageIcon(image))); bottomPanel.setLayout(new GridLayout(2, 1)); rowCenPanel.add(homeBtn); rowCenPanel.add(genBtn); bottomPanel.add(rowCenPanel); add(topPanel, BorderLayout.NORTH); add(bottomPanel, BorderLayout.SOUTH); add(centerPanel, BorderLayout.CENTER); Data.mainFrame.setSize(1000, 500); genBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Date date = new Date(); String newDate = new SimpleDateFormat("yyyy-MM-dd h-m-a").format(date); JFileChooser fileChooser = new JFileChooser(); fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); File myFile = new File(Data.registrationNumber + ".png"); fileChooser.setSelectedFile(myFile); fileChooser.showSaveDialog(null); String dlDir = fileChooser.getSelectedFile().getPath(); System.out.println(dlDir); String fileName = fileChooser.getSelectedFile().getName(); String filePath = ""; if (fileName != null) { filePath = dlDir + ".png"; } else { filePath = dlDir + "/" + Data.registrationNumber + ".png"; } String fileType = "png"; myFile = new File(filePath); if (dlDir != null) { try { ImageIO.write(image, fileType, myFile); JOptionPane.showMessageDialog(Data.mainFrame, "QR Code Saved in " + dlDir); } catch (IOException e1) { e1.printStackTrace(); } } } }); homeBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Data.mainFrame.showPanel("inventory"); } }); try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (ClassNotFoundException e1) { e1.printStackTrace(); } catch (InstantiationException e1) { e1.printStackTrace(); } catch (IllegalAccessException e1) { e1.printStackTrace(); } catch (UnsupportedLookAndFeelException e1) { e1.printStackTrace(); } }
From source file:richtercloud.reflection.form.builder.typehandler.StringTypeHandler.java
@Override public void reset(JTextField component) { component.setText(""); }
From source file:ropes.MainWindow.java
private void jTextField_sliderValueKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField_sliderValueKeyReleased JTextField txt = (JTextField) evt.getSource(); if (txt.getText().equals("")) { txt.setText("0"); return;/*from w w w .j a v a 2s . c o m*/ } jSlider_size_select.setValue(Integer.valueOf(txt.getText())); }
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);// ww w . ja v a 2 s . c om // 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); }