Java Code Examples for javax.swing.SwingConstants#RIGHT

The following examples show how to use javax.swing.SwingConstants#RIGHT . These examples are extracted from open source projects. 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
protected void alignRectsRunFor(final Rectangle[] rects, final Dimension tabPaneSize, final int tabPlacement, final boolean isRightToLeft) {
    final boolean isVertical = tabPlacement == SwingConstants.LEFT || tabPlacement == SwingConstants.RIGHT;

    if (isVertical) {
        if (needsScrollers) {
            stretchScrollingVerticalRun(rects, tabPaneSize);
        } else {
            centerVerticalRun(rects, tabPaneSize);
        }
    } else {
        if (needsScrollers) {
            stretchScrollingHorizontalRun(rects, tabPaneSize, isRightToLeft);
        } else {
            centerHorizontalRun(rects, tabPaneSize, isRightToLeft);
        }
    }
}
 
Example 2
protected void alignRectsRunFor(final Rectangle[] rects, final Dimension tabPaneSize, final int tabPlacement, final boolean isRightToLeft) {
    final boolean isVertical = tabPlacement == SwingConstants.LEFT || tabPlacement == SwingConstants.RIGHT;

    if (isVertical) {
        if (needsScrollers) {
            stretchScrollingVerticalRun(rects, tabPaneSize);
        } else {
            centerVerticalRun(rects, tabPaneSize);
        }
    } else {
        if (needsScrollers) {
            stretchScrollingHorizontalRun(rects, tabPaneSize, isRightToLeft);
        } else {
            centerHorizontalRun(rects, tabPaneSize, isRightToLeft);
        }
    }
}
 
Example 3
protected void alignRectsRunFor(final Rectangle[] rects, final Dimension tabPaneSize, final int tabPlacement, final boolean isRightToLeft) {
    final boolean isVertical = tabPlacement == SwingConstants.LEFT || tabPlacement == SwingConstants.RIGHT;

    if (isVertical) {
        if (needsScrollers) {
            stretchScrollingVerticalRun(rects, tabPaneSize);
        } else {
            centerVerticalRun(rects, tabPaneSize);
        }
    } else {
        if (needsScrollers) {
            stretchScrollingHorizontalRun(rects, tabPaneSize, isRightToLeft);
        } else {
            centerHorizontalRun(rects, tabPaneSize, isRightToLeft);
        }
    }
}
 
Example 4
Source Project: pumpernickel   File: BoxTabbedPaneUI.java    License: MIT License 6 votes vote down vote up
@Override
public void formatTabContent(JTabbedPane tabs, JComponent c) {
	if (contentBorder) {
		Border border;
		if (tabs.getTabPlacement() == SwingConstants.LEFT) {
			border = new PartialLineBorder(borderNormalDark, true,
					false, true, true);
		} else if (tabs.getTabPlacement() == SwingConstants.BOTTOM) {
			border = new PartialLineBorder(borderNormalDark, true,
					true, false, true);
		} else if (tabs.getTabPlacement() == SwingConstants.RIGHT) {
			border = new PartialLineBorder(borderNormalDark, true,
					true, true, false);
		} else {
			border = new PartialLineBorder(borderNormalDark, false,
					true, true, true);
		}
		c.setBorder(border);
	}
}
 
Example 5
protected void alignRectsRunFor(final Rectangle[] rects, final Dimension tabPaneSize, final int tabPlacement, final boolean isRightToLeft) {
    final boolean isVertical = tabPlacement == SwingConstants.LEFT || tabPlacement == SwingConstants.RIGHT;

    if (isVertical) {
        if (needsScrollers) {
            stretchScrollingVerticalRun(rects, tabPaneSize);
        } else {
            centerVerticalRun(rects, tabPaneSize);
        }
    } else {
        if (needsScrollers) {
            stretchScrollingHorizontalRun(rects, tabPaneSize, isRightToLeft);
        } else {
            centerHorizontalRun(rects, tabPaneSize, isRightToLeft);
        }
    }
}
 
Example 6
Source Project: ChatUI   File: PlayerList.java    License: MIT License 6 votes vote down vote up
private TableRenderer createTableRenderer(TableScrollHelper scroll) {
    return new DefaultTableRenderer() {

        private final TableViewport viewport = scroll.createViewport();

        @Override
        public TableViewport getViewport() {
            return this.viewport;
        }

        @Override
        protected int getCellAlignment(int row, int column) {
            if (column == 0) {
                return SwingConstants.RIGHT;
            }
            return SwingConstants.CENTER;
        }

    };
}
 
Example 7
Source Project: FlatLaf   File: FlatTableHeaderUI.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void paint( Graphics g, JComponent c ) {
	// do not paint borders if JTableHeader.setDefaultRenderer() was used
	TableCellRenderer defaultRenderer = header.getDefaultRenderer();
	boolean paintBorders = isSystemDefaultRenderer( defaultRenderer );
	if( !paintBorders && header.getColumnModel().getColumnCount() > 0 ) {
		// check whether the renderer delegates to the system default renderer
		Component rendererComponent = defaultRenderer.getTableCellRendererComponent(
			header.getTable(), "", false, false, -1, 0 );
		paintBorders = isSystemDefaultRenderer( rendererComponent );
	}

	if( paintBorders )
		paintColumnBorders( g, c );

	// temporary use own default renderer if necessary
	FlatTableCellHeaderRenderer sortIconRenderer = null;
	if( sortIconPosition != SwingConstants.RIGHT ) {
		sortIconRenderer = new FlatTableCellHeaderRenderer( header.getDefaultRenderer() );
		header.setDefaultRenderer( sortIconRenderer );
	}

	// paint header
	super.paint( g, c );

	// restore default renderer
	if( sortIconRenderer != null ) {
		sortIconRenderer.reset();
		header.setDefaultRenderer( sortIconRenderer.delegate );
	}

	if( paintBorders )
		paintDraggedColumnBorders( g, c );
}
 
Example 8
/**
 * Converts {@code Label} alignment constant to the {@code JLabel} constant.
 * If wrong Label alignment provided returns default alignment.
 *
 * @param alignment {@code Label} constant.
 *
 * @return {@code JLabel} constant.
 */
private static int convertAlignment(final int alignment) {
    switch (alignment) {
        case Label.CENTER:
            return SwingConstants.CENTER;
        case Label.RIGHT:
            return SwingConstants.RIGHT;
        default:
            return SwingConstants.LEFT;
    }
}
 
Example 9
Source Project: mars-sim   File: Clock.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void setBounds(final Rectangle BOUNDS) {
    if (BOUNDS.width <= BOUNDS.height) {
        // vertical
        int yNew;
        switch(verticalAlignment) {
            case SwingConstants.TOP:
                yNew = BOUNDS.y;
                break;
            case SwingConstants.BOTTOM:
                yNew = BOUNDS.y + (BOUNDS.height - BOUNDS.width);
                break;
            case SwingConstants.CENTER:
            default:
                yNew = BOUNDS.y + ((BOUNDS.height - BOUNDS.width) / 2);
                break;
        }
        super.setBounds(BOUNDS.x, yNew, BOUNDS.width, BOUNDS.width);
    } else {
        // horizontal
        int xNew;
        switch(horizontalAlignment) {
            case SwingConstants.LEFT:
                xNew = BOUNDS.x;
                break;
            case SwingConstants.RIGHT:
                xNew = BOUNDS.x + (BOUNDS.width - BOUNDS.height);
                break;
            case SwingConstants.CENTER:
            default:
                xNew = BOUNDS.x + ((BOUNDS.width - BOUNDS.height) / 2);
                break;
        }
        super.setBounds(xNew, BOUNDS.y, BOUNDS.height, BOUNDS.height);
    }
    calcInnerBounds();
    init(getGaugeBounds().width, getGaugeBounds().height);
    setInitialized(true);
}
 
Example 10
/**
 * Constructor
 * @param siteName the site name.
 * @param completion the completion level.
 */
ExplorationSitePanel(String siteName, double completion) {
	// Use JPanel constructor.
	super();

	this.completion = completion;

	setLayout(new GridLayout(1, 2, 3, 3));

	WebPanel namePanel = new WebPanel(new FlowLayout(FlowLayout.RIGHT, 3, 3));
	namePanel.setAlignmentX(CENTER_ALIGNMENT);
	add(namePanel);

	WebLabel nameLabel = new WebLabel("  " + Conversion.capitalize(siteName), SwingConstants.RIGHT);
	nameLabel.setAlignmentX(CENTER_ALIGNMENT);
	namePanel.add(nameLabel);

	WebPanel barPanel = new WebPanel(new FlowLayout(FlowLayout.LEFT, 3, 0));
	barPanel.setAlignmentX(CENTER_ALIGNMENT);
	add(barPanel);

	completionBar = new WebProgressBar(0, 100);
	completionBar.setAlignmentX(CENTER_ALIGNMENT);
	completionBar.setStringPainted(true);
	completionBar.setValue((int) (completion * 100D));
	barPanel.add(completionBar);
}
 
Example 11
/**
 * Converts {@code Label} alignment constant to the {@code JLabel} constant.
 * If wrong Label alignment provided returns default alignment.
 *
 * @param alignment {@code Label} constant.
 *
 * @return {@code JLabel} constant.
 */
private static int convertAlignment(final int alignment) {
    switch (alignment) {
        case Label.CENTER:
            return SwingConstants.CENTER;
        case Label.RIGHT:
            return SwingConstants.RIGHT;
        default:
            return SwingConstants.LEFT;
    }
}
 
Example 12
Source Project: gcs   File: LibraryFields.java    License: Mozilla Public License 2.0 5 votes vote down vote up
private JTextField addLabelAndField(String title, String value, int columns) {
    JLabel label = new JLabel(title, SwingConstants.RIGHT);
    mOwner.add(label, new PrecisionLayoutData().setEndHorizontalAlignment());
    JTextField field = new JTextField(value);
    mOwner.add(field, new PrecisionLayoutData().setGrabHorizontalSpace(true).setFillHorizontalAlignment().setHorizontalSpan(columns));
    field.getDocument().addDocumentListener(this);
    mComps.add(label);
    mComps.add(field);
    return field;
}
 
Example 13
Source Project: Bytecoder   File: ColorChooserPanel.java    License: Apache License 2.0 5 votes vote down vote up
ColorChooserPanel(ColorModel model) {
    this.model = model;
    this.panel = new ColorPanel(this.model);
    this.slider = new DiagramComponent(this.panel, false);
    this.diagram = new DiagramComponent(this.panel, true);
    this.text = new JFormattedTextField();
    this.label = new JLabel(null, null, SwingConstants.RIGHT);
    ValueFormatter.init(6, true, this.text);
}
 
Example 14
Source Project: ChatUI   File: ConfigTableRenderer.java    License: MIT License 5 votes vote down vote up
@Override
protected int getCellAlignment(int row, int column) {
    if (column == 0) {
        return SwingConstants.RIGHT;
    }
    return SwingConstants.LEFT;
}
 
Example 15
Source Project: mars-sim   File: Led.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void setBounds(final int X, final int Y, final int WIDTH, final int HEIGHT) {
    if (WIDTH <= HEIGHT) {
        // vertical
        int yNew;
        switch(verticalAlignment) {
            case SwingConstants.TOP:
                yNew = Y;
                break;
            case SwingConstants.BOTTOM:
                yNew = Y + (HEIGHT - WIDTH);
                break;
            case SwingConstants.CENTER:
            default:
                yNew = Y + ((HEIGHT - WIDTH) / 2);
                break;
        }
        super.setBounds(X, yNew, WIDTH, WIDTH);
    } else {
        // horizontal
        int xNew;
        switch(horizontalAlignment) {
            case SwingConstants.LEFT:
                xNew = X;
                break;
            case SwingConstants.RIGHT:
                xNew = X + (WIDTH - HEIGHT);
                break;
            case SwingConstants.CENTER:
            default:
                xNew = X + ((WIDTH - HEIGHT) / 2);
                break;
        }
        super.setBounds(xNew, Y, HEIGHT, HEIGHT);
    }
    calcInnerBounds();
    init(INNER_BOUNDS.width);
    initialized = true;
}
 
Example 16
Source Project: netbeans   File: HTMLLabel.java    License: Apache License 2.0 5 votes vote down vote up
public void setText(String value) {
    txt = value;
    
    Font font = getFont();
    Color fgColor = getForeground();
    Color bgColor = getBackground();
    
    value = value.replaceAll("\\n\\r|\\r\\n|\\n|\\r", "<br>"); //NOI18N
    value = value.replace("<code>", "<code style=\"font-size: " + font.getSize() + "pt;\">"); //NOI18N
    
    String fgText = "rgb(" + fgColor.getRed() + "," + fgColor.getGreen() + "," + fgColor.getBlue() + ")"; //NOI18N
    String bgText = isOpaque() ? "rgb(" + bgColor.getRed() + "," + bgColor.getGreen() + "," + bgColor.getBlue() + ")" : null; //NOI18N
    
    String alignText = null;
    switch (halign) {
        case SwingConstants.CENTER:
            alignText = "center"; //NOI18N
            break;
        case SwingConstants.RIGHT:
        case SwingConstants.TRAILING:
            alignText = "right"; //NOI18N
            break;
    }
    
    String bodyFlags = "text=\"" + fgText + "\""; //NOI18N
    if (bgText != null) bodyFlags += " bgcolor=\"" + bgText + "\""; //NOI18N
    if (alignText != null) bodyFlags += " align=\"" + alignText + "\""; //NOI18N
    
    super.setText("<html><body " + bodyFlags + " style=\"font-size: " + font.getSize() //NOI18N
                  + "pt; font-family: " + font.getName() + ";\">" + value + "</body></html>"); //NOI18N
}
 
Example 17
Source Project: ChatUI   File: DefaultTableRenderer.java    License: MIT License 4 votes vote down vote up
@Override
public Text applySideBorders(int rowIndex, List<Text> line, int[] colMaxWidths, PlayerContext ctx) {
    Text.Builder builder = Text.builder();
    Text bar = TextUtils.charCache('│');
    for (int i = 0; i < colMaxWidths.length; i++) {
        Text part = null;
        int partWidth = 0;
        if (i < line.size()) {
            part = line.get(i);
        }
        if (part != null) {
            partWidth = ctx.utils().getWidth(part);
        }
        StringBuilder spaces = new StringBuilder();
        TextUtils.padSpaces(spaces, colMaxWidths[i] - partWidth);
        builder.append(bar);
        int alignment = getCellAlignment(rowIndex, i);
        if (alignment == SwingConstants.RIGHT || alignment == SwingConstants.CENTER) {
            if (spaces.length() > 0) {
                if (alignment == SwingConstants.CENTER) {
                    String half = spaces.substring(0, (int) (spaces.length() + 0.5) / 2);
                    spaces.delete(0, half.length());
                    builder.append(Text.of(half));
                } else {
                    builder.append(Text.of(spaces.toString()));
                }
            }
        }
        if (part != null) {
            builder.append(part);
        }
        if (alignment == SwingConstants.LEFT || alignment == SwingConstants.CENTER) {
            if (spaces.length() > 0) {
                builder.append(Text.of(spaces.toString()));
            }
        }
        if (i == colMaxWidths.length - 1) {
            builder.append(bar);
        }
    }
    return builder.build();

}
 
Example 18
Source Project: gcs   File: HitLocationPanel.java    License: Mozilla Public License 2.0 4 votes vote down vote up
private void createDRField(CharacterSheet sheet, String key, String tooltip) {
    PageField field = new PageField(sheet, key, SwingConstants.RIGHT, false, tooltip);
    add(field, new PrecisionLayoutData().setHorizontalAlignment(PrecisionLayoutAlignment.FILL));
}
 
Example 19
Source Project: gcs   File: PageSetupPanel.java    License: Mozilla Public License 2.0 4 votes vote down vote up
private static EditorField createMarginField(double margin, JPanel wrapper) {
    EditorField field = new EditorField(new DefaultFormatterFactory(new DoubleFormatter(0, 999.999, false)), null, SwingConstants.RIGHT, Double.valueOf(margin), Double.valueOf(999.999), null);
    UIUtilities.setToPreferredSizeOnly(field);
    wrapper.add(field);
    return field;
}
 
Example 20
/**
 * Creates a new {@link ReferenceLookupPreferences}.
 *
 * @param owner The owning {@link PreferencesWindow}.
 */
public ReferenceLookupPreferences(PreferencesWindow owner) {
    super(I18n.Text("Page References"), owner);
    setLayout(new BorderLayout());
    mPanel = new BandedPanel(I18n.Text("Page References"));
    mPanel.setLayout(new ColumnLayout(4, 5, 0));
    mPanel.setBorder(new EmptyBorder(2, 5, 2, 5));
    mPanel.setOpaque(true);
    mPanel.setBackground(Color.WHITE);
    Preferences prefs = Preferences.getInstance();
    for (PdfRef ref : prefs.allPdfRefs(false)) {
        JButton button = new JButton(I18n.Text("Remove"));
        UIUtilities.setToPreferredSizeOnly(button);
        button.addActionListener(event -> {
            prefs.removePdfRef(ref);
            Component[] children = mPanel.getComponents();
            int         length   = children.length;
            for (int i = 0; i < length; i++) {
                if (children[i] == button) {
                    for (int j = i + 4; --j >= i; ) {
                        mPanel.remove(j);
                    }
                    mPanel.setSize(mPanel.getPreferredSize());
                    break;
                }
            }
        });
        mPanel.add(button);
        JLabel idLabel = new JLabel(ref.getId(), SwingConstants.CENTER);
        idLabel.setBorder(new CompoundBorder(new LineBorder(), new EmptyBorder(1, 4, 1, 4)));
        idLabel.setOpaque(true);
        idLabel.setBackground(Color.YELLOW);
        mPanel.add(idLabel);
        EditorField field = new EditorField(new DefaultFormatterFactory(new IntegerFormatter(-9999, 9999, true)), event -> ref.setPageToIndexOffset(((Integer) event.getNewValue()).intValue()), SwingConstants.RIGHT, Integer.valueOf(ref.getPageToIndexOffset()), Integer.valueOf(-9999), I18n.Text("If your PDF is opening up to the wrong page when opening page references, enter an offset here to compensate."));
        mPanel.add(field);
        mPanel.add(new JLabel(ref.getPath().normalize().toAbsolutePath().toString()));
    }
    mPanel.setSize(mPanel.getPreferredSize());
    JScrollPane scroller      = new JScrollPane(mPanel);
    Dimension   preferredSize = scroller.getPreferredSize();
    if (preferredSize.height > 200) {
        preferredSize.height = 200;
    }
    scroller.setPreferredSize(preferredSize);
    add(scroller);
}