Example usage for javax.swing BorderFactory createDashedBorder

List of usage examples for javax.swing BorderFactory createDashedBorder

Introduction

In this page you can find the example usage for javax.swing BorderFactory createDashedBorder.

Prototype

public static Border createDashedBorder(Paint paint, float length, float spacing) 

Source Link

Document

Creates a dashed border of the specified paint , relative length , and relative spacing .

Usage

From source file:Main.java

public Main() {
    getContentPane().setLayout(new FlowLayout());
    JLabel labelTwo = new JLabel("www.java2s.com");
    labelTwo.setBorder(BorderFactory.createDashedBorder(Color.red, 30F, 1F));

    add(labelTwo);/*from  w w w . j a v  a  2s .c om*/

    JLabel labelThree = new JLabel("MatteBorder");
    labelThree.setBorder(BorderFactory.createMatteBorder(10, 10, 10, 10, Color.pink));
    add(labelThree);

    JLabel labelFour = new JLabel("TitledBorder");
    labelFour.setBorder(
            BorderFactory.createTitledBorder(BorderFactory.createMatteBorder(10, 10, 10, 10, Color.pink),
                    "Title", TitledBorder.RIGHT, TitledBorder.BOTTOM));
    add(labelFour);

    JLabel labelSix = new JLabel("CompoundBorder");
    Border one = BorderFactory.createEtchedBorder();
    Border two = BorderFactory.createMatteBorder(4, 4, 4, 4, Color.blue);
    labelSix.setBorder(BorderFactory.createCompoundBorder(one, two));
    add(labelSix);

}

From source file:de.bwravencl.controllerbuddy.gui.Main.java

private void initOverlay() {
    if (!preferences.getBoolean(PREFERENCES_SHOW_OVERLAY, Toolkit.getDefaultToolkit().isAlwaysOnTopSupported()))
        return;/*from www. j a va  2 s. c o  m*/

    var longestDescription = "";
    for (final var mode : input.getProfile().getModes()) {
        final var description = mode.getDescription();
        if (description.length() > longestDescription.length())
            longestDescription = description;
    }

    final var fontMetrics = labelCurrentMode.getFontMetrics(labelCurrentMode.getFont());
    labelCurrentMode.setPreferredSize(
            new Dimension(fontMetrics.stringWidth(longestDescription), fontMetrics.getHeight()));
    labelCurrentMode.setForeground(Color.RED);
    labelCurrentMode.setText(input.getProfile().getActiveMode().getDescription());

    overlayFrame = new JFrame("Overlay");
    overlayFrame.setType(JFrame.Type.UTILITY);
    overlayFrame.setLayout(new BorderLayout());
    overlayFrame.setFocusableWindowState(false);
    overlayFrame.setUndecorated(true);
    overlayFrame.setBackground(TRANSPARENT);

    overlayFrame.add(labelCurrentMode, BorderLayout.PAGE_END);
    overlayFrame.setAlwaysOnTop(true);

    indicatorPanelFlowLayout = new FlowLayout();
    indicatorPanel = new JPanel(indicatorPanelFlowLayout);
    indicatorPanel.setBackground(TRANSPARENT);

    final var virtualAxisToOverlayAxisMap = input.getProfile().getVirtualAxisToOverlayAxisMap();
    for (final var virtualAxis : Input.VirtualAxis.values()) {
        final var overlayAxis = virtualAxisToOverlayAxisMap.get(virtualAxis);
        if (overlayAxis != null) {
            final var progressBar = new JProgressBar(SwingConstants.VERTICAL) {

                private static final long serialVersionUID = 8167193907929992395L;

                @Override
                public void setMaximum(final int n) {
                    if (overlayAxis.inverted)
                        super.setMinimum(-n);
                    else
                        super.setMaximum(n);
                }

                @Override
                public void setMinimum(final int n) {
                    if (overlayAxis.inverted)
                        super.setMaximum(-n);
                    else
                        super.setMinimum(n);
                }

                @Override
                public void setValue(final int n) {
                    super.setValue(overlayAxis.inverted ? -n : n);
                }
            };
            progressBar.setPreferredSize(new Dimension(21, 149));
            progressBar.setBorder(BorderFactory.createDashedBorder(Color.BLACK,
                    (float) progressBar.getPreferredSize().getWidth(),
                    (float) progressBar.getPreferredSize().getWidth()));
            progressBar.setBackground(Color.LIGHT_GRAY);
            progressBar.setForeground(overlayAxis.color);
            progressBar.setValue(1);
            indicatorPanel.add(progressBar);
            virtualAxisToProgressBarMap.put(virtualAxis, progressBar);
        }
    }

    overlayFrame.add(indicatorPanel);

    overlayFrameDragListener = new FrameDragListener(this, overlayFrame) {

        @Override
        public void mouseDragged(final MouseEvent e) {
            super.mouseDragged(e);
            final var maxWindowBounds = GraphicsEnvironment.getLocalGraphicsEnvironment()
                    .getMaximumWindowBounds();
            updateOverlayAlignment(maxWindowBounds);
        }

    };
    overlayFrame.addMouseListener(overlayFrameDragListener);
    overlayFrame.addMouseMotionListener(overlayFrameDragListener);

    prevMaxWindowBounds = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
    updateOverlayLocation(prevMaxWindowBounds);

    overlayFrame.setVisible(true);
}