Example usage for javax.swing JToolBar setRollover

List of usage examples for javax.swing JToolBar setRollover

Introduction

In this page you can find the example usage for javax.swing JToolBar setRollover.

Prototype

@BeanProperty(preferred = true, visualUpdate = true, description = "Will draw rollover button borders in the toolbar.")
public void setRollover(boolean rollover) 

Source Link

Document

Sets the rollover state of this toolbar.

Usage

From source file:ToolBarSample.java

public static void main(final String args[]) {
    JFrame frame = new JFrame("JToolBar Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JToolBar toolbar = new JToolBar();
    toolbar.setRollover(true);

    JButton button = new JButton("button");
    toolbar.add(button);//from w w  w.j a  va2s .c  om
    toolbar.addSeparator();

    toolbar.add(new JButton("button 2"));

    toolbar.add(new JComboBox(new String[] { "A", "B", "C" }));

    Container contentPane = frame.getContentPane();
    contentPane.add(toolbar, BorderLayout.NORTH);
    JTextArea textArea = new JTextArea();
    JScrollPane pane = new JScrollPane(textArea);
    contentPane.add(pane, BorderLayout.CENTER);
    frame.setSize(350, 150);
    frame.setVisible(true);
}

From source file:Main.java

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

    JToolBar toolBar = new JToolBar("Still draggable");

    toolBar.setFloatable(false);//from w ww.  j  ava2  s . com
    toolBar.setRollover(true);

    toolBar.add(new JButton("New"));
    toolBar.addSeparator();
    toolBar.add(new JButton("Open"));

    frame.add(toolBar, "North");

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

From source file:MainClass.java

public static void main(String[] a) {
    final int STRING_POSITION = 1;
    Object buttonColors[][] = { { Color.RED, "RED" }, { Color.BLUE, "BLUE" }, { Color.GREEN, "GREEN" },
            { Color.BLACK, "BLACK" }, null, // separator
            { Color.CYAN, "CYAN" } };

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    ActionListener actionListener = new TheActionListener();

    JToolBar toolbar = new JToolBar();
    toolbar.setRollover(true);

    for (Object[] color : buttonColors) {
        if (color == null) {
            toolbar.addSeparator();//from  w  ww  .ja v a2s .c o m
        } else {
            Icon icon = MetalIconFactory.getTreeComputerIcon();
            JButton button = new JButton(icon);
            button.setActionCommand((String) color[STRING_POSITION]);
            button.addActionListener(actionListener);
            toolbar.add(button);
        }
    }

    Action action = new ShowAction(toolbar);
    JButton button = new JButton(action);
    toolbar.add(button);

    Container contentPane = frame.getContentPane();
    contentPane.add(toolbar, BorderLayout.NORTH);
    JTextArea textArea = new JTextArea();
    JScrollPane pane = new JScrollPane(textArea);
    contentPane.add(pane, BorderLayout.CENTER);
    frame.setSize(350, 150);
    frame.setVisible(true);

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    // Create a horizontal toolbar
    JToolBar toolbar = new JToolBar();

    // Get current rollover mode
    boolean b = toolbar.isRollover();

    // Enable rollover mode
    toolbar.setRollover(true);
}

From source file:components.ToolBarDemo2.java

public ToolBarDemo2() {
    super(new BorderLayout());

    //Create the toolbar.
    JToolBar toolBar = new JToolBar("Still draggable");
    addButtons(toolBar);//  ww  w.  j av a 2 s . co  m
    toolBar.setFloatable(false);
    toolBar.setRollover(true);

    //Create the text area used for output.  Request
    //enough space for 5 rows and 30 columns.
    textArea = new JTextArea(5, 30);
    textArea.setEditable(false);
    JScrollPane scrollPane = new JScrollPane(textArea);

    //Lay out the main panel.
    setPreferredSize(new Dimension(450, 130));
    add(toolBar, BorderLayout.PAGE_START);
    add(scrollPane, BorderLayout.CENTER);
}

From source file:ToolBarDemo2.java

public ToolBarDemo2() {
    super(new BorderLayout());

    //Create the toolbar.
    JToolBar toolBar = new JToolBar("Still draggable");
    addButtons(toolBar);/*w w w .  j  av  a2 s .  co  m*/
    toolBar.setFloatable(false);
    toolBar.setRollover(true);

    //Create the text area used for output. Request
    //enough space for 5 rows and 30 columns.
    textArea = new JTextArea(5, 30);
    textArea.setEditable(false);
    JScrollPane scrollPane = new JScrollPane(textArea);

    //Lay out the main panel.
    setPreferredSize(new Dimension(450, 130));
    add(toolBar, BorderLayout.PAGE_START);
    add(scrollPane, BorderLayout.CENTER);
}

From source file:daylightchart.gui.DaylightChartGui.java

/**
 * Creates a new instance of a Daylight Chart main window.
 *
 * @param location/*from w  ww . j  a  va2s .c  om*/
 *        Location for a single chart window, or null for the full UI
 * @param slimUi
 *        Whether to use a slim user interface
 */
public DaylightChartGui(final Location location, final boolean slimUi) {

    this.slimUi = slimUi;

    setIconImage(new ImageIcon(DaylightChartGui.class.getResource("/daylightchart.png")) //$NON-NLS-1$
            .getImage());

    setTitle("Daylight Chart"); //$NON-NLS-1$
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    if (location == null) {
        // Create basic UI
        locationsTabbedPane = new LocationsTabbedPane();
        locationsList = new LocationsList(this);

        if (slimUi) {
            getContentPane().add(locationsList);
        } else {
            final JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, locationsList,
                    locationsTabbedPane);
            splitPane.setOneTouchExpandable(true);
            getContentPane().add(splitPane);
        }

        // Create menus and toolbars
        final JMenuBar menuBar = new JMenuBar();
        setJMenuBar(menuBar);
        final JToolBar toolBar = new JToolBar();
        toolBar.setRollover(true);
        add(toolBar, BorderLayout.NORTH);

        createFileMenu(menuBar, toolBar);
        createActions(menuBar, toolBar);
        createOptionsMenu(menuBar, toolBar);
        createHelpMenu(menuBar, toolBar);

        // Open the first location
        Location firstTabLocation;
        final Collection<Location> recentLocations = UserPreferences.recentLocationsFile().getData();
        if (recentLocations.size() > 0) {
            firstTabLocation = recentLocations.iterator().next();
        } else {
            firstTabLocation = locationsList.getSelectedLocation();
        }
        addLocationTab(firstTabLocation);
    } else {
        locationsTabbedPane = null;
        locationsList = null;
        final DaylightChartReport daylightChartReport = new DaylightChartReport(location,
                UserPreferences.optionsFile().getData());
        final ChartPanel chartPanel = new ChartPanel(daylightChartReport.getChart());
        chartPanel.setPreferredSize(ChartConfiguration.chartDimension);
        setContentPane(chartPanel);
    }

    pack();
}

From source file:com.mightypocket.ashot.Mediator.java

private JToolBar createToolBar() {
    ApplicationActionMap actionMap = getActionMap();
    JToolBar bar = new JToolBar();
    bar.setRollover(true);
    toolBarMap.clear();/*from w  w w. j a v  a 2  s  .c o  m*/
    final boolean hideText = !p.getBoolean(PREF_GUI_SHOW_TEXT_IN_TOOLBAR, true);
    for (String actionName : TOOLBAR) {
        if (TOOLBAR_SEPARATOR.equals(actionName)) {
            bar.addSeparator();
        } else {
            AbstractButton bt;
            if (actionName.startsWith(TOOLBAR_TOGGLE_BUTTON)) {
                actionName = StringUtils.substring(actionName, TOOLBAR_TOGGLE_BUTTON.length());
                bt = new JToggleButton(actionMap.get(actionName));
            } else {
                bt = new JButton(actionMap.get(actionName));
            }
            bt.setFocusable(false);
            bt.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
            bt.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
            bt.setHideActionText(hideText);
            bar.add(bt);
            toolBarMap.put(actionName, bt);
        }
    }

    return bar;
}

From source file:net.pms.newgui.LooksFrame.java

public JComponent buildContent() {
    JPanel panel = new JPanel(new BorderLayout());
    JToolBar toolBar = new JToolBar();
    toolBar.setFloatable(false);/*from  w ww .  ja v  a 2  s  . c om*/
    toolBar.setRollover(true);

    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:com.net2plan.gui.tools.GUINetworkDesign.java

private JPanel configureLeftBottomPanel() {
    this.focusPanel = new FocusPane(this);
    final JPanel focusPanelContainer = new JPanel(new BorderLayout());
    final JToolBar navigationToolbar = new JToolBar(JToolBar.VERTICAL);
    navigationToolbar.setRollover(true);
    navigationToolbar.setFloatable(false);
    navigationToolbar.setOpaque(false);//from w ww . j  av  a2  s  .c  om

    final JButton btn_pickNavigationUndo, btn_pickNavigationRedo;

    btn_pickNavigationUndo = new JButton("");
    btn_pickNavigationUndo
            .setIcon(new ImageIcon(TopologyPanel.class.getResource("/resources/gui/undoPick.png")));
    btn_pickNavigationUndo.setToolTipText("Navigate back to the previous element picked");
    btn_pickNavigationRedo = new JButton("");
    btn_pickNavigationRedo
            .setIcon(new ImageIcon(TopologyPanel.class.getResource("/resources/gui/redoPick.png")));
    btn_pickNavigationRedo.setToolTipText("Navigate forward to the next element picked");

    final ActionListener action = e -> {
        Pair<NetworkElement, Pair<Demand, Link>> backOrForward;
        do {
            backOrForward = (e.getSource() == btn_pickNavigationUndo)
                    ? GUINetworkDesign.this.getVisualizationState().getPickNavigationBackElement()
                    : GUINetworkDesign.this.getVisualizationState().getPickNavigationForwardElement();
            if (backOrForward == null)
                break;
            final NetworkElement ne = backOrForward.getFirst(); // For network elements
            final Pair<Demand, Link> fr = backOrForward.getSecond(); // For forwarding rules
            if (ne != null) {
                if (ne.getNetPlan() != GUINetworkDesign.this.getDesign())
                    continue;
                if (ne.getNetPlan() == null)
                    continue;
                break;
            } else if (fr != null) {
                if (fr.getFirst().getNetPlan() != GUINetworkDesign.this.getDesign())
                    continue;
                if (fr.getFirst().getNetPlan() == null)
                    continue;
                if (fr.getSecond().getNetPlan() != GUINetworkDesign.this.getDesign())
                    continue;
                if (fr.getSecond().getNetPlan() == null)
                    continue;
                break;
            } else
                break; // null,null => reset picked state
        } while (true);
        if (backOrForward != null) {
            if (backOrForward.getFirst() != null)
                GUINetworkDesign.this.getVisualizationState().pickElement(backOrForward.getFirst());
            else if (backOrForward.getSecond() != null)
                GUINetworkDesign.this.getVisualizationState().pickForwardingRule(backOrForward.getSecond());
            else
                GUINetworkDesign.this.getVisualizationState().resetPickedState();

            GUINetworkDesign.this.updateVisualizationAfterPick();
        }
    };

    btn_pickNavigationUndo.addActionListener(action);
    btn_pickNavigationRedo.addActionListener(action);

    btn_pickNavigationRedo.setFocusable(false);
    btn_pickNavigationUndo.setFocusable(false);

    navigationToolbar.add(btn_pickNavigationUndo);
    navigationToolbar.add(btn_pickNavigationRedo);

    final JScrollPane scPane = new JScrollPane(focusPanel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    scPane.getVerticalScrollBar().setUnitIncrement(20);
    scPane.getHorizontalScrollBar().setUnitIncrement(20);
    scPane.setBorder(BorderFactory.createEmptyBorder());

    // Control the scroll
    scPane.getHorizontalScrollBar().addAdjustmentListener(e -> {
        // Repaints the panel each time the horizontal scroll bar is moves, in order to avoid ghosting.
        focusPanelContainer.revalidate();
        focusPanelContainer.repaint();
    });

    focusPanelContainer.add(navigationToolbar, BorderLayout.WEST);
    focusPanelContainer.add(scPane, BorderLayout.CENTER);

    JPanel pane = new JPanel(new MigLayout("fill, insets 0 0 0 0"));
    pane.setBorder(BorderFactory.createTitledBorder(new LineBorder(Color.BLACK), "Focus panel"));

    pane.add(focusPanelContainer, "grow");
    return pane;
}