Java Code Examples for javax.swing.JSeparator#getPreferredSize()

The following examples show how to use javax.swing.JSeparator#getPreferredSize() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GenericToolbar.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void addSeparator() {
    if (!UIUtils.isMetalLookAndFeel()) {
        super.addSeparator();
    } else {
        final JSeparator separator = new JSeparator(JSeparator.VERTICAL);
        final int WDTH = separator.getPreferredSize().width;
        final Dimension SIZE = new Dimension(new JToolBar.Separator().getSeparatorSize().width, 12);
        JPanel panel = new JPanel(null) {
            public Dimension getPreferredSize() { return SIZE; }
            public Dimension getMaximumSize() { return SIZE; }
            public Dimension getMinimumSize() { return SIZE; }

            public void doLayout() {
                int x = (getWidth() - WDTH) / 2;
                int y = (getHeight()- SIZE.height) / 2;
                separator.setBounds(x, y, WDTH, SIZE.height);
            }
        };
        panel.setOpaque(false);
        panel.add(separator);
        super.add(panel);
    }
}
 
Example 2
Source File: GenericToolbar.java    From visualvm with GNU General Public License v2.0 6 votes vote down vote up
public void addSeparator() {
    if (!UIUtils.isMetalLookAndFeel()) {
        super.addSeparator();
    } else {
        final JSeparator separator = new JSeparator(JSeparator.VERTICAL);
        final int WDTH = separator.getPreferredSize().width;
        final Dimension SIZE = new Dimension(new JToolBar.Separator().getSeparatorSize().width, 12);
        JPanel panel = new JPanel(null) {
            public Dimension getPreferredSize() { return SIZE; }
            public Dimension getMaximumSize() { return SIZE; }
            public Dimension getMinimumSize() { return SIZE; }

            public void doLayout() {
                int x = (getWidth() - WDTH) / 2;
                int y = (getHeight()- SIZE.height) / 2;
                separator.setBounds(x, y, WDTH, SIZE.height);
            }
        };
        panel.setOpaque(false);
        panel.add(separator);
        super.add(panel);
    }
}