List of usage examples for javax.swing JToolBar setFloatable
@BeanProperty(preferred = true, description = "Can the tool bar be made to float by the user?") public void setFloatable(boolean b)
floatable
property, which must be true
for the user to move the tool bar. From source file:lab4.YouQuiz.java
private void switchToQuizMode() { JToolBar toolbar = new JToolBar(); toolbar.setFloatable(false); backButton.setFocusable(false);// www.java 2 s. c o m toolbar.add(backButton); toolbar.setAlignmentX(0); backButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { contentPanel.setQuestion(questionsArray.get(--questionIndex)); forwardButton.setEnabled(true); if (questionIndex - 1 < 0) { backButton.setEnabled(false); } updateAnswerForm(); } }); forwardButton.setFocusable(false); toolbar.add(forwardButton); toolbar.setAlignmentX(0); forwardButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { contentPanel.setQuestion(questionsArray.get(++questionIndex)); backButton.setEnabled(true); if (questionsArray.size() == questionIndex + 1) { forwardButton.setEnabled(false); } updateAnswerForm(); } }); speakButton.setFocusable(false); toolbar.add(speakButton); toolbar.setAlignmentX(0); speakButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { Audio audio = Audio.getInstance(); InputStream sound = null; try { sound = audio.getAudio(questionsArray.get(questionIndex).getQuestion(), Language.ENGLISH); } catch (IOException ex) { Logger.getLogger(YouQuiz.class.getName()).log(Level.SEVERE, null, ex); } try { audio.play(sound); } catch (JavaLayerException ex) { Logger.getLogger(YouQuiz.class.getName()).log(Level.SEVERE, null, ex); } } }); refreshButton.setFocusable(false); toolbar.add(refreshButton); toolbar.setAlignmentX(0); refreshButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { shuffleQuestions(); questionIndex = 0; backButton.setEnabled(false); if (questionsArray.size() == 1) { forwardButton.setEnabled(false); } else { forwardButton.setEnabled(true); } contentPanel.setQuestion(questionsArray.get(questionIndex)); updateAnswerForm(); } }); micButton.setFocusable(false); toolbar.add(micButton); toolbar.setAlignmentX(0); micButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { GSpeechDuplex dup = new GSpeechDuplex(); dup.addResponseListener(new GSpeechResponseListener() { @Override public void onResponse(GoogleResponse gr) { if (questionsArray.get(questionIndex).checkAnswer(gr.getResponse())) { JOptionPane.showMessageDialog(null, "Thats Great, Correct Answer", "Excellent", JOptionPane.INFORMATION_MESSAGE); } else { JOptionPane.showMessageDialog(null, "Oops! '" + gr.getResponse() + "' is a wrong Answer. Its '" + questionsArray.get(questionIndex).getAnswer().get(0) + "'", "Sorry", JOptionPane.ERROR_MESSAGE); } } }); Microphone mic = new Microphone(FLACFileWriter.FLAC); File file = new File("CRAudioTest.flac"); try { mic.captureAudioToFile(file); Thread.sleep(5000); mic.close(); byte[] data = Files.readAllBytes(mic.getAudioFile().toPath()); dup.recognize(data, (int) mic.getAudioFormat().getSampleRate()); mic.getAudioFile().delete(); } catch (LineUnavailableException | InterruptedException | IOException ex) { } } }); contentPanel = new ContentPanel(); contentPanel.add(Box.createRigidArea(new Dimension(0, 10))); contentPanel.add(toolbar, BorderLayout.NORTH); contentPanel.add(Box.createRigidArea(new Dimension(0, 50))); contentPanel.add(contentPanel.questionLabel); add(contentPanel, BorderLayout.CENTER); if (questionsArray.isEmpty()) { refreshButton.setEnabled(false); backButton.setEnabled(false); forwardButton.setEnabled(false); speakButton.setEnabled(false); } else { questionIndex = 0; backButton.setEnabled(false); if (questionsArray.size() == 1) { forwardButton.setEnabled(false); } contentPanel.setQuestion(questionsArray.get(questionIndex)); contentPanel.add(Box.createRigidArea(new Dimension(0, 20))); contentPanel.add(contentPanel.answerPanel); contentPanel.add(Box.createRigidArea(new Dimension(0, 10))); contentPanel.add(contentPanel.checkButton); updateAnswerForm(); } }
From source file:dk.dma.epd.common.prototype.gui.notification.ChatServicePanel.java
/** * Constructor// w ww . ja v a 2 s. co m * * @param compactLayout * if false, there will be message type selectors in the panel */ public ChatServicePanel(boolean compactLayout) { super(new BorderLayout()); // Prepare the title header titleHeader.setBackground(getBackground().darker()); titleHeader.setOpaque(true); titleHeader.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); titleHeader.setHorizontalAlignment(SwingConstants.CENTER); add(titleHeader, BorderLayout.NORTH); // Add messages panel scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); messagesPanel.setBackground(UIManager.getColor("List.background")); messagesPanel.setOpaque(false); messagesPanel.setLayout(new GridBagLayout()); messagesPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); add(scrollPane, BorderLayout.CENTER); JPanel sendPanel = new JPanel(new GridBagLayout()); add(sendPanel, BorderLayout.SOUTH); Insets insets = new Insets(2, 2, 2, 2); // Add text area if (compactLayout) { messageText = new JTextField(); ((JTextField) messageText).addActionListener(this); sendPanel.add(messageText, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, NORTH, BOTH, insets, 0, 0)); } else { messageText = new JTextArea(); JScrollPane scrollPane2 = new JScrollPane(messageText); scrollPane2.setPreferredSize(new Dimension(100, 50)); scrollPane2.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); scrollPane2.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); sendPanel.add(scrollPane2, new GridBagConstraints(0, 0, 1, 2, 1.0, 1.0, NORTH, BOTH, insets, 0, 0)); } // Add buttons ButtonGroup group = new ButtonGroup(); messageTypeBtn = createMessageTypeButton("Send messages", ICON_MESSAGE, true, group); warningTypeBtn = createMessageTypeButton("Send warnings", ICON_WARNING, false, group); alertTypeBtn = createMessageTypeButton("Send alerts", ICON_ALERT, false, group); if (!compactLayout) { JToolBar msgTypePanel = new JToolBar(); msgTypePanel.setBorderPainted(false); msgTypePanel.setOpaque(true); msgTypePanel.setFloatable(false); sendPanel.add(msgTypePanel, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, NORTH, NONE, insets, 0, 0)); msgTypePanel.add(messageTypeBtn); msgTypePanel.add(warningTypeBtn); msgTypePanel.add(alertTypeBtn); } if (compactLayout) { sendBtn = new JButton("Send"); sendPanel.add(sendBtn, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, NORTH, NONE, insets, 0, 0)); } else { sendBtn = new JButton("Send", ICON_MESSAGE); sendBtn.setPreferredSize(new Dimension(100, sendBtn.getPreferredSize().height)); sendPanel.add(sendBtn, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, NORTH, NONE, insets, 0, 0)); } sendBtn.setEnabled(false); messageText.setEditable(false); sendBtn.addActionListener(this); }
From source file:org.eurocarbdb.application.glycoworkbench.plugin.AnnotationReportApplet.java
private JToolBar createToolBar() { JToolBar toolbar = new JToolBar(); toolbar.setFloatable(false); toolbar.add(theActionManager.get("print")); toolbar.addSeparator();//from w w w. j ava 2s .co m toolbar.add(theActionManager.get("undo")); toolbar.add(theActionManager.get("redo")); toolbar.addSeparator(); toolbar.add(theActionManager.get("cut")); toolbar.add(theActionManager.get("copy")); toolbar.add(theActionManager.get("delete")); toolbar.add(theActionManager.get("screenshot")); toolbar.addSeparator(); toolbar.add(theActionManager.get("enlarge")); toolbar.add(theActionManager.get("resetsize")); toolbar.add(theActionManager.get("shrink")); toolbar.addSeparator(); toolbar.add(theActionManager.get("zoomnone")); toolbar.add(theActionManager.get("zoomin")); toolbar.add(theActionManager.get("zoomout")); toolbar.addSeparator(); toolbar.add(theActionManager.get("orientation")); return toolbar; }
From source file:edu.ucla.stat.SOCR.chart.SuperPowerChart.java
protected void createActionComponents(JToolBar toolBar) { JButton button = null;//from ww w . j a va 2s .c o m toolBar.setFloatable(false); /**************** Demo Tab****************/ if (useStaticExample) { exampleStaticAction = new AbstractAction() { public void actionPerformed(ActionEvent e) { // Create First Example reset(); resetTable(); resetMappingList(); resetExample(); if (tabbedPanelContainer.getTitleAt(tabbedPanelContainer.getSelectedIndex()) == ALL) setMixPanel(); updateStatus(url); validate(); } }; button = toolBar.add(exampleStaticAction); button.setText(EXAMPLE); button.setToolTipText(chartDescription); } /**************** DO-CHART Tab ****************/ computeAction = new AbstractAction() { public void actionPerformed(ActionEvent e) { doChart(); } }; button = toolBar.add(computeAction); button.setText(DOCHART); button.setToolTipText("Press this Button to Generate the Chart"); /**************** CLEAR Tab****************/ clearAction = new AbstractAction() { public void actionPerformed(ActionEvent e) { /* somehow reset has to be called more than once to set to the correct header. I'll leave it like this before I figure out why. annie che 20051123 -_- */ reset(); // Need to work out what this means // reset(); resetTable(); resetMappingList(); resetChart(); ChartExampleData exampleNull = new ChartExampleData(0, 0); /* A Null Example (with no data) is used here to reset the table so that when "CLEAR" button is pressed, the cells of dataTable is NOT null. annieche 20060110. */ updateExample(exampleNull); if (tabbedPanelContainer.getTitleAt(tabbedPanelContainer.getSelectedIndex()) == ALL) setMixPanel(); updateStatus("The Chart has been reset!"); //updateExample(exampleNull); } }; button = toolBar.add(clearAction); button.setText(CLEAR); button.setToolTipText("Clears All Windows"); /**************** wiki Tab ****************/ Action linkAction = new AbstractAction() { public void actionPerformed(ActionEvent e) { try { //popInfo("SOCRChart: About", new java.net.URL("http://wiki.stat.ucla.edu/socr/index.php/SOCR_EduMaterials_Activities_PowerTransformFamily_Graphs"), "SOCR: Power Transform Graphing Activity"); parentApplet.getAppletContext().showDocument(new java.net.URL( "http://wiki.stat.ucla.edu/socr/index.php/SOCR_EduMaterials_Activities_PowerTransformFamily_Graphs"), "SOCR: Power Transform Graphing Activity"); } catch (MalformedURLException Exc) { JOptionPane.showMessageDialog(null, Exc, "MalformedURL Error", JOptionPane.ERROR_MESSAGE); Exc.printStackTrace(); } } }; button = toolBar.add(linkAction); //button.setMinimumSize(new Dimension(110, 20)); button.setText(" WIKI_Activity "); button.setToolTipText("Press this Button to go to SOCR_POWER_Activity wiki page"); /**************** TEST Tab ****************/ testAction = new AbstractAction() { public void actionPerformed(ActionEvent e) { doTest(); } }; if (TEST_API) { button = toolBar.add(testAction); button.setText(TEST); button.setToolTipText("Press this Button to test the API"); } }
From source file:TopLevelTransferHandlerDemo.java
private JToolBar createDummyToolBar() { JToolBar tb = new JToolBar(); JButton b;//w w w . ja v a 2 s. c om b = new JButton("New"); b.setRequestFocusEnabled(false); tb.add(b); b = new JButton("Open"); b.setRequestFocusEnabled(false); tb.add(b); b = new JButton("Save"); b.setRequestFocusEnabled(false); tb.add(b); b = new JButton("Print"); b.setRequestFocusEnabled(false); tb.add(b); b = new JButton("Preview"); b.setRequestFocusEnabled(false); tb.add(b); tb.setFloatable(false); return tb; }
From source file:jmemorize.gui.swing.frames.MainFrame.java
private JPanel buildOperationsBar() { final JToolBar operationsToolbar = new JToolBar(); operationsToolbar.setFloatable(false); operationsToolbar.add(new JButton(new NewLessonAction())); operationsToolbar.add(new JButton(new OpenLessonAction(jMemorizeIO, this))); operationsToolbar.add(new JButton(new SaveLessonAction(jMemorizeIO))); operationsToolbar.add(new JButton(new AddCardAction(this))); operationsToolbar.add(new JButton(new EditCardAction(this))); operationsToolbar.add(new JButton(new ResetCardAction(this))); operationsToolbar.add(new JButton(new RemoveAction(this))); operationsToolbar.add(new JButton(new AddCategoryAction(this))); operationsToolbar.add(new JButton(new FindAction(this))); operationsToolbar.add(new JButton(new LearnAction(this))); final JPanel operationsPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 1, 1)); operationsPanel.add(operationsToolbar); return operationsPanel; }
From source file:jmemorize.gui.swing.frames.MainFrame.java
private JPanel buildCategoryBar() { final JToolBar categoryToolbar = new JToolBar(); categoryToolbar.setFloatable(false); categoryToolbar.setMargin(new Insets(2, 2, 2, 2)); m_showTreeButton = new JButton(new ShowCategoryTreeAction()); m_showTreeButton.setPreferredSize(new Dimension(120, 21)); categoryToolbar.add(m_showTreeButton); final JLabel categoryLabel = new JLabel(Localization.get(LC.CATEGORY), SwingConstants.CENTER); categoryLabel.setPreferredSize(new Dimension(60, 15)); categoryToolbar.add(categoryLabel);/*from www.j av a 2 s . c om*/ m_categoryBox = new CategoryComboBox(); m_categoryBox.setPreferredSize(new Dimension(24, 24)); m_categoryBox.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent evt) { categoryBoxActionPerformed(); } }); categoryToolbar.add(m_categoryBox); categoryToolbar.add(new JButton(new SplitMainFrameAction(this))); final JPanel categoryPanel = new JPanel(new BorderLayout()); categoryPanel.setBorder(new EtchedBorder()); categoryPanel.add(categoryToolbar, BorderLayout.NORTH); return categoryPanel; }
From source file:coolmap.application.widget.impl.WidgetUserGroup.java
private void init() { table.getTableHeader().setReorderingAllowed(false); table.setAutoCreateRowSorter(true);//from ww w .j a v a2s .com table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); table.setDefaultRenderer(Object.class, new DefaultTableCellRenderer() { @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { JLabel label = (JLabel) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); if (isSelected) { return label; } if (column == 1) { try { label.setBackground( nodeColor.get(table.getModel().getValueAt(table.convertRowIndexToModel(row), 0))); } catch (Exception e) { } } else { label.setBackground(UI.colorWhite); } return label; } }); //Need a search box as well. // getContentPane().setLayout(new BorderLayout()); // getContentPane().add(new JScrollPane(table), BorderLayout.CENTER); JToolBar t = new JToolBar(); getContentPane().add(t, BorderLayout.NORTH); t.setFloatable(false); try { //also add an action to add group nodes JMenuItem item = new JMenuItem("selected row nodes"); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { CoolMapObject o = CoolMapMaster.getActiveCoolMapObject(); if (o == null) { return; } ArrayList<Range<Integer>> selected = o.getCoolMapView().getSelectedRows(); ArrayList<VNode> selectedNodes = new ArrayList<>(); for (Range<Integer> r : selected) { for (int i = r.lowerEndpoint(); i < r.upperEndpoint(); i++) { selectedNodes.add(o.getViewNodeRow(i)); } } createNewGroup(selectedNodes); //create a group } }); WidgetMaster.getViewport().addPopupMenuItem("Create group", item, false); item = new JMenuItem("selected column nodes"); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { CoolMapObject o = CoolMapMaster.getActiveCoolMapObject(); if (o == null) { return; } ArrayList<Range<Integer>> selected = o.getCoolMapView().getSelectedColumns(); ArrayList<VNode> selectedNodes = new ArrayList<>(); for (Range<Integer> r : selected) { for (int i = r.lowerEndpoint(); i < r.upperEndpoint(); i++) { selectedNodes.add(o.getViewNodeColumn(i)); } } createNewGroup(selectedNodes); } }); WidgetMaster.getViewport().addPopupMenuItem("Create group", item, false); } catch (Exception e) { // //Error handling. } }
From source file:net.pms.newgui.LooksFrame.java
public JComponent buildContent() { JPanel panel = new JPanel(new BorderLayout()); JToolBar toolBar = new JToolBar(); toolBar.setFloatable(false); toolBar.setRollover(true);//from w w w. ja v a2 s . co m toolBar.add(new JPanel()); if (PMS.getConfiguration().useWebInterface()) { webinterface = createToolBarButton(Messages.getString("LooksFrame.29"), "button-wif.png"); webinterface.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String error = null; if (PMS.get().getWebInterface() != null && isNotBlank(PMS.get().getWebInterface().getUrl())) { try { URI uri = new URI(PMS.get().getWebInterface().getUrl()); try { Desktop.getDesktop().browse(uri); } catch (RuntimeException | IOException be) { LOGGER.error("Cound not open the default web browser: {}", be.getMessage()); LOGGER.trace("", be); error = Messages.getString("LooksFrame.BrowserError") + "\n" + be.getMessage(); } } catch (URISyntaxException se) { LOGGER.error("Could not form a valid web interface URI from \"{}\": {}", PMS.get().getWebInterface().getUrl(), se.getMessage()); LOGGER.trace("", se); error = Messages.getString("LooksFrame.URIError"); } } else { error = Messages.getString("LooksFrame.URIError"); } if (error != null) { JOptionPane.showMessageDialog(null, error, Messages.getString("Dialog.Error"), JOptionPane.ERROR_MESSAGE); } } }); webinterface.setToolTipText(Messages.getString("LooksFrame.30")); webinterface.setEnabled(configuration.useWebInterface()); toolBar.add(webinterface); toolBar.addSeparator(new Dimension(20, 1)); } restartIcon = (AnimatedIcon) reload.getIcon(); restartRequredIcon.start(); setReloadable(false); reload.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { reload.setEnabled(false); PMS.get().reset(); } }); reload.setToolTipText(Messages.getString("LooksFrame.28")); toolBar.add(reload); toolBar.addSeparator(new Dimension(20, 1)); AbstractButton quit = createToolBarButton(Messages.getString("LooksFrame.5"), "button-quit.png"); quit.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { quit(); } }); toolBar.add(quit); if (System.getProperty(START_SERVICE) != null) { quit.setEnabled(false); } toolBar.add(new JPanel()); // Apply the orientation to the toolbar and all components in it ComponentOrientation orientation = ComponentOrientation.getOrientation(PMS.getLocale()); toolBar.applyComponentOrientation(orientation); toolBar.setBorder(new EmptyBorder(new Insets(8, 0, 0, 0))); panel.add(toolBar, BorderLayout.NORTH); panel.add(buildMain(), BorderLayout.CENTER); status = new JLabel(""); status.setBorder(BorderFactory.createEmptyBorder()); status.setComponentOrientation(orientation); // Calling applyComponentOrientation() here would be ideal. // Alas it horribly mutilates the layout of several tabs. //panel.applyComponentOrientation(orientation); panel.add(status, BorderLayout.SOUTH); return panel; }
From source file:net.sf.nmedit.nomad.core.Nomad.java
private JToolBar createQuickActionToolbar() { JToolBar toolbar = new JToolBar(); toolbar.setBorderPainted(false);/*from ww w .j a v a 2 s. c om*/ toolbar.setFloatable(false); toolbar.add(Factory.createToolBarButton(menuLayout.getEntry(MENU_FILE_OPEN))); toolbar.addSeparator(); toolbar.add(Factory.createToolBarButton(menuLayout.getEntry(MENU_FILE_SAVE))); toolbar.addSeparator(); JPopupMenu pop = new JPopupMenu(); Iterator<FileService> iter = ServiceRegistry.getServices(FileService.class); JRadioButtonMenuItem rfirst = null; SelectedAction sa = new SelectedAction(); sa.putValue(AbstractAction.SMALL_ICON, getImage("/icons/tango/16x16/actions/document-new.png")); while (iter.hasNext()) { FileService fs = iter.next(); if (fs.isNewFileOperationSupported()) { JRadioButtonMenuItem rb = new JRadioButtonMenuItem( new AHAction(fs.getName(), fs.getIcon(), fs, "newFile")); sa.add(rb); pop.add(rb); if (rfirst == null) rfirst = rb; } } JButton btn = Factory.createToolBarButton(sa); toolbar.add(btn); new JDropDownButtonControl(btn, pop); return toolbar; }