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:utybo.branchingstorytree.swing.editor.StoryEditor.java
public StoryEditor(BranchingStory baseStory) throws BSTException { setLayout(new MigLayout("hidemode 3", "[grow]", "[][grow]")); JToolBar toolBar = new JToolBar(); toolBar.setBorder(null);//from w w w. ja v a2 s .co m toolBar.setFloatable(false); add(toolBar, "cell 0 0,growx"); JButton btnSaveAs = new JButton(Lang.get("saveas"), new ImageIcon(Icons.getImage("Save As", 16))); btnSaveAs.addActionListener(e -> { saveAs(); }); toolBar.add(btnSaveAs); JButton btnSave = new JButton(Lang.get("save"), new ImageIcon(Icons.getImage("Save", 16))); btnSave.addActionListener(e -> { save(); }); toolBar.add(btnSave); JButton btnPlay = new JButton(Lang.get("play"), new ImageIcon(Icons.getImage("Circled Play", 16))); btnPlay.addActionListener(ev -> { try { String s = exportToString(); File f = Files.createTempDirectory("openbst").toFile(); File bstFile = new File(f, "expoted.bst"); try (FileOutputStream fos = new FileOutputStream(bstFile);) { IOUtils.write(s, fos, StandardCharsets.UTF_8); } OpenBSTGUI.getInstance().openStory(bstFile); } catch (Exception e) { OpenBST.LOG.error("Export failed", e); Messagers.showException(OpenBSTGUI.getInstance(), Lang.get("editor.exportfail"), e); } }); toolBar.add(btnPlay); JButton btnFilePreview = new JButton(Lang.get("editor.exportpreview"), new ImageIcon(Icons.getImage("PreviewText", 16))); btnFilePreview.addActionListener(e -> { try { String s = exportToString(); JDialog dialog = new JDialog(OpenBSTGUI.getInstance(), Lang.get("editor.exportpreview")); JTextArea jta = new JTextArea(s); jta.setLineWrap(true); jta.setWrapStyleWord(true); dialog.add(new JScrollPane(jta)); dialog.setModalityType(ModalityType.APPLICATION_MODAL); dialog.setSize((int) (Icons.getScale() * 350), (int) (Icons.getScale() * 300)); dialog.setLocationRelativeTo(OpenBSTGUI.getInstance()); dialog.setVisible(true); } catch (Exception x) { OpenBST.LOG.error("Failed to preview", x); Messagers.showException(OpenBSTGUI.getInstance(), Lang.get("editor.previewerror"), x); } }); toolBar.add(btnFilePreview); Component horizontalGlue = Box.createHorizontalGlue(); toolBar.add(horizontalGlue); JButton btnClose = new JButton(Lang.get("close"), new ImageIcon(Icons.getImage("Cancel", 16))); btnClose.addActionListener(e -> { askClose(); }); toolBar.add(btnClose); for (final Component component : toolBar.getComponents()) { if (component instanceof JButton) { ((JButton) component).setHideActionText(false); ((JButton) component).setToolTipText(((JButton) component).getText()); ((JButton) component).setText(""); } } JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP); tabbedPane.setTabPlacement(JTabbedPane.LEFT); add(tabbedPane, "cell 0 1,grow"); tabbedPane.addTab("Beta Warning", new StoryEditorWelcomeScreen()); details = new StoryDetailsEditor(this); tabbedPane.addTab(Lang.get("editor.details"), details); nodesEditor = new StoryNodesEditor(); tabbedPane.addTab(Lang.get("editor.nodes"), nodesEditor); this.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke("control S"), "doSave"); this.getActionMap().put("doSave", new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { save(); } }); importFrom(baseStory); }
From source file:verdandi.ui.ProjectViewerPanel.java
private JToolBar getToolbar() { // JPanel toolbar = new JPanel(); // toolbar.setLayout(new BoxLayout(toolbar, BoxLayout.LINE_AXIS)); JToolBar toolbar = new JToolBar(SwingConstants.HORIZONTAL); toolbar.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.gridx = 0;/* ww w . ja v a2 s .co m*/ c.gridy = 0; c.fill = GridBagConstraints.NONE; c.anchor = GridBagConstraints.WEST; c.weightx = 0.0; c.weighty = 0.0; URL imageURL = null; imageURL = Thread.currentThread().getContextClassLoader() .getResource(THEME_RC.getString("icon.project.add")); ImageIcon addProjectIcon = new ImageIcon(imageURL, "add"); JButton addProject = new JButton(addProjectIcon); addProject.setActionCommand(CMD_ADD_PROJECT); addProject.setToolTipText(RB.getString("projectviewer.add.tooltip")); addProject.addActionListener(this); toolbar.add(addProject, c); c.gridx++; imageURL = getClass().getClassLoader().getResource(THEME_RC.getString("icon.project.edit")); ImageIcon editProjectIcon = new ImageIcon(imageURL, "edit"); JButton editProject = new JButton(editProjectIcon); editProject.setActionCommand(CMD_EDIT_PROJECT); editProject.setToolTipText(RB.getString("projectviewer.edit.tooltip")); editProject.addActionListener(this); toolbar.add(editProject, c); c.gridx++; imageURL = getClass().getClassLoader().getResource(THEME_RC.getString("icon.projects.import")); ImageIcon importProjectIcon = new ImageIcon(imageURL, "import"); JButton importProject = new JButton(importProjectIcon); importProject.setActionCommand(CMD_IMPORT_PROJECT); importProject.setToolTipText(RB.getString("projectviewer.import.tooltip")); importProject.addActionListener(this); toolbar.add(importProject, c); c.gridx++; // THEME_RC.getString("") imageURL = getClass().getClassLoader().getResource(THEME_RC.getString("icon.projects.export")); ImageIcon exportProjectIcon = new ImageIcon(imageURL, "export"); JButton exportProject = new JButton(exportProjectIcon); exportProject.setActionCommand(CMD_EXPORT_PROJECT); exportProject.setToolTipText(RB.getString("projectviewer.export.tooltip")); exportProject.addActionListener(this); toolbar.add(exportProject, c); c.gridx++; toolbar.add(new JToolBar.Separator(), c); c.gridx++; imageURL = getClass().getClassLoader().getResource(THEME_RC.getString("icon.project.hide.active")); hideActiveIcon = new ImageIcon(imageURL, "hide active"); imageURL = getClass().getClassLoader().getResource(THEME_RC.getString("icon.project.show.active")); showActiveIcon = new ImageIcon(imageURL, "show active"); toggleShowActive = new JToggleButton(hideActiveIcon); toggleShowActive.setActionCommand(CMD_TOGGLE_SHOW_ACTIVE); toggleShowActive.setToolTipText(RB.getString("projectviewer.toggleshowactive.tooltip")); toggleShowActive.addActionListener(this); toolbar.add(toggleShowActive, c); c.gridx++; c.weightx = 0.5; toolbar.add(Box.createHorizontalGlue(), c); c.weightx = 0.0; c.gridx++; c.insets = new Insets(0, 5, 0, 5); toolbar.add(new JLabel("Filter"), c); c.gridx++; c.insets = new Insets(0, 0, 0, 0); searchField = new JTextField(10); searchField.getDocument().addDocumentListener(this); searchField.setToolTipText(RB.getString("projectviewer.searchfield.tooltip")); toolbar.add(searchField, c); toolbar.setFloatable(false); return toolbar; }
From source file:xtrememp.PlaylistManager.java
private void initComponents() { JToolBar toolBar = new JToolBar(); toolBar.setFloatable(false); openPlaylistButton = new JButton(Utilities.DOCUMENT_OPEN_ICON); openPlaylistButton.setToolTipText(tr("MainFrame.PlaylistManager.OpenPlaylist")); openPlaylistButton.addActionListener(this); toolBar.add(openPlaylistButton);// w w w.j a v a2 s .c o m savePlaylistButton = new JButton(Utilities.DOCUMENT_SAVE_ICON); savePlaylistButton.setToolTipText(tr("MainFrame.PlaylistManager.SavePlaylist")); savePlaylistButton.addActionListener(this); toolBar.add(savePlaylistButton); toolBar.addSeparator(); addToPlaylistButton = new JButton(Utilities.LIST_ADD_ICON); addToPlaylistButton.setToolTipText(tr("MainFrame.PlaylistManager.AddToPlaylist")); addToPlaylistButton.addActionListener(this); toolBar.add(addToPlaylistButton); remFromPlaylistButton = new JButton(Utilities.LIST_REMOVE_ICON); remFromPlaylistButton.setToolTipText(tr("MainFrame.PlaylistManager.RemoveFromPlaylist")); remFromPlaylistButton.addActionListener(this); remFromPlaylistButton.setEnabled(false); toolBar.add(remFromPlaylistButton); clearPlaylistButton = new JButton(Utilities.EDIT_CLEAR_ICON); clearPlaylistButton.setToolTipText(tr("MainFrame.PlaylistManager.ClearPlaylist")); clearPlaylistButton.addActionListener(this); clearPlaylistButton.setEnabled(false); toolBar.add(clearPlaylistButton); toolBar.addSeparator(); moveUpButton = new JButton(Utilities.GO_UP_ICON); moveUpButton.setToolTipText(tr("MainFrame.PlaylistManager.MoveUp")); moveUpButton.addActionListener(this); moveUpButton.setEnabled(false); toolBar.add(moveUpButton); moveDownButton = new JButton(Utilities.GO_DOWN_ICON); moveDownButton.setToolTipText(tr("MainFrame.PlaylistManager.MoveDown")); moveDownButton.addActionListener(this); moveDownButton.setEnabled(false); toolBar.add(moveDownButton); toolBar.addSeparator(); mediaInfoButton = new JButton(Utilities.MEDIA_INFO_ICON); mediaInfoButton.setToolTipText(tr("MainFrame.PlaylistManager.MediaInfo")); mediaInfoButton.addActionListener(this); mediaInfoButton.setEnabled(false); toolBar.add(mediaInfoButton); toolBar.add(Box.createHorizontalGlue()); searchTextField = new SearchTextField(15); searchTextField.setMaximumSize(new Dimension(120, searchTextField.getPreferredSize().height)); searchTextField.getTextField().getDocument().addDocumentListener(new SearchFilterListener()); toolBar.add(searchTextField); toolBar.add(Box.createHorizontalStrut(6)); this.add(toolBar, BorderLayout.NORTH); playlistTable = new JTable(playlistTableModel, playlistTableColumnModel); playlistTable.setDefaultRenderer(String.class, new PlaylistCellRenderer()); playlistTable.setActionMap(null); playlistTable.getTableHeader().addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent ev) { if (SwingUtilities.isRightMouseButton(ev) || (MouseInfo.getNumberOfButtons() == 1 && ev.isControlDown())) { playlistTableColumnModel.getPopupMenu().show(playlistTable.getTableHeader(), ev.getX(), ev.getY()); return; } int clickedColumn = playlistTableColumnModel.getColumnIndexAtX(ev.getX()); PlaylistTableColumn playlistColumn = playlistTableColumnModel.getColumn(clickedColumn); playlistTableColumnModel.resetAll(playlistColumn.getModelIndex()); playlistColumn.setSortOrderUp(!playlistColumn.isSortOrderUp()); playlistTableModel.sort(playlistColumn.getComparator()); colorizeRow(); } }); playlistTable.setFillsViewportHeight(true); playlistTable.setShowGrid(false); playlistTable.setRowSelectionAllowed(true); playlistTable.setColumnSelectionAllowed(false); playlistTable.setDragEnabled(false); playlistTable.setFont(playlistTable.getFont().deriveFont(Font.BOLD)); playlistTable.setIntercellSpacing(new Dimension(0, 0)); playlistTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); playlistTable.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent ev) { int selectedRow = playlistTable.rowAtPoint(ev.getPoint()); if (SwingUtilities.isLeftMouseButton(ev) && ev.getClickCount() == 2) { if (selectedRow != -1) { playlist.setCursorPosition(selectedRow); controlListener.acOpenAndPlay(); } } } }); playlistTable.getSelectionModel().addListSelectionListener(this); playlistTable.getColumnModel().getSelectionModel().addListSelectionListener(this); playlistTable.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { // View Media Info if (e.getKeyCode() == KeyEvent.VK_I && e.getModifiers() == KeyEvent.CTRL_MASK) { viewMediaInfo(); } // Select all else if (e.getKeyCode() == KeyEvent.VK_A && e.getModifiers() == KeyEvent.CTRL_MASK) { playlistTable.selectAll(); } else if (e.getKeyCode() == KeyEvent.VK_UP) { // Move selected track(s) up if (e.getModifiers() == KeyEvent.ALT_MASK) { moveUp(); } // Select previous track else { if (playlistTable.getSelectedRow() > 0) { int previousRowIndex = playlistTable.getSelectedRow() - 1; playlistTable.clearSelection(); playlistTable.addRowSelectionInterval(previousRowIndex, previousRowIndex); makeRowVisible(previousRowIndex); } } } else if (e.getKeyCode() == KeyEvent.VK_DOWN) { // Move selected track(s) down if (e.getModifiers() == KeyEvent.ALT_MASK) { moveDown(); } // Select next track else { if (playlistTable.getSelectedRow() < playlistTable.getRowCount() - 1) { int nextRowIndex = playlistTable.getSelectedRow() + 1; playlistTable.clearSelection(); playlistTable.addRowSelectionInterval(nextRowIndex, nextRowIndex); makeRowVisible(nextRowIndex); } } } // Play selected track else if (e.getKeyCode() == KeyEvent.VK_ENTER) { int selectedRow = playlistTable.getSelectedRow(); if (selectedRow != -1) { playlist.setCursorPosition(selectedRow); controlListener.acOpenAndPlay(); } } // Add new tracks else if (e.getKeyCode() == KeyEvent.VK_INSERT) { addFilesDialog(false); } // Delete selected tracks else if (e.getKeyCode() == KeyEvent.VK_DELETE) { remove(); } } }); XtremeMP.getInstance().getMainFrame().setDropTarget(new DropTarget(playlistTable, this)); JScrollPane ptScrollPane = new JScrollPane(playlistTable); ptScrollPane.setActionMap(null); this.add(ptScrollPane, BorderLayout.CENTER); }