下面列出了javax.swing.BoxLayout#LINE_AXIS 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void addLine(List<Segment> line) {
if (line.size() == 1) {
addSegment(this, line.get(0));
} else {
Box lineBox = new Box(BoxLayout.LINE_AXIS);
if (lineBox.getComponentOrientation().isLeftToRight()) {
lineBox.setAlignmentX(LEFT_ALIGNMENT);
} else {
lineBox.setAlignmentX(RIGHT_ALIGNMENT);
}
for (Segment s : line) {
addSegment(lineBox, s);
}
add(lineBox);
}
}
@Override
protected void updateSupplementUtilityJPanel() {
JPanel supplementUtilityJPanel = getSupplementUtilityJPanel();
supplementUtilityJPanel.removeAll();
LayoutManager layout = new BoxLayout(supplementUtilityJPanel, BoxLayout.LINE_AXIS);
supplementUtilityJPanel.setLayout(layout);
supplementUtilityJPanel.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY, 1));
supplementUtilityJPanel.revalidate();
supplementUtilityJPanel.repaint();
}
/** This method calculates position (index) for a component dragged
* over a container (or just for mouse cursor being moved over container,
* without any component).
* @param container instance of a real container over/in which the
* component is dragged
* @param containerDelegate effective container delegate of the container
* (for layout managers we always use container delegate instead of
* the container)
* @param component the real component being dragged; not needed here
* @param index position (index) of the component in its current container;
* not needed here
* @param posInCont position of mouse in the container delegate
* @param posInComp position of mouse in the dragged component;
* not needed here
* @return index corresponding to the position of the component in the
* container
*/
@Override
public int getNewIndex(Container container,
Container containerDelegate,
Component component,
int index,
Point posInCont,
Point posInComp)
{
if (!(containerDelegate.getLayout() instanceof BoxLayout))
return -1;
assistantParams = 0;
Component[] components = containerDelegate.getComponents();
for (int i = 0; i < components.length; i++) {
if (components[i] == component) {
assistantParams--;
continue;
}
Rectangle b = components[i].getBounds();
if ((axis == BoxLayout.X_AXIS) || (axis == BoxLayout.LINE_AXIS)) {
if (posInCont.x < b.x + b.width / 2) {
assistantParams += i;
return i;
}
}
else {
if (posInCont.y < b.y + b.height / 2) {
assistantParams += i;
return i;
}
}
}
assistantParams += components.length;
return components.length;
}
private void tweak() {
if (UIUtils.isGTKLookAndFeel() || UIUtils.isNimbusLookAndFeel()) {
int axis = getOrientation() == VERTICAL ? BoxLayout.PAGE_AXIS :
BoxLayout.LINE_AXIS;
setLayout(new BoxLayout(this, axis));
}
if (UIUtils.isNimbusLookAndFeel())
setBorder(BorderFactory.createEmptyBorder(-2, 0, -2, 0));
else if (UIUtils.isAquaLookAndFeel())
setBorder(BorderFactory.createEmptyBorder(0, 1, 0, 1));
if (UIUtils.isWindowsClassicLookAndFeel()) setRollover(true);
}
public TitledSeparator(String title, int fontType) {
super(BoxLayout.LINE_AXIS);
this.font = getFont(fontType);
if (fontType == BORDER)
color = UIManager.getColor("TitledBorder.titleColor");
build(title);
}
public TitledSeparator(String title, Font font, Color color) {
super(BoxLayout.LINE_AXIS);
this.font = font;
this.color = color;
build(title);
}
protected Box getObject() {
return new Box(BoxLayout.LINE_AXIS);
}
protected BoxLayout getObject() {
return new BoxLayout(new JLabel("TEST"), BoxLayout.LINE_AXIS);
}
protected BoxLayout getObject() {
return new BoxLayout(new JLabel("TEST"), BoxLayout.LINE_AXIS);
}
protected Box getObject() {
return new Box(BoxLayout.LINE_AXIS);
}
protected Box getObject() {
return new Box(BoxLayout.LINE_AXIS);
}
protected Box getObject() {
return new Box(BoxLayout.LINE_AXIS);
}
@Override
protected JPanel getAdditionalUtilityPanel() {
JPanel additionalUtilityPanel = new JPanel();
LayoutManager layout = new BoxLayout(additionalUtilityPanel, BoxLayout.LINE_AXIS);
additionalUtilityPanel.setLayout(layout);
JButton expandAllJButton = getExpandAllJButton();
additionalUtilityPanel.add(expandAllJButton);
return additionalUtilityPanel;
}
private JPanel getTracerUtilsJPanel() {
JPanel tracerReportJPanel = new JPanel();
LayoutManager layout = new BoxLayout(tracerReportJPanel, BoxLayout.LINE_AXIS);
tracerReportJPanel.setLayout(layout);
JPanel additionalUtilityPanel = getAdditionalUtilityPanel();
Dimension dim = new Dimension(5, 30);
tracerReportJPanel.add(Box.createHorizontalGlue());
tracerReportJPanel.add(Box.createRigidArea(dim));
if (additionalUtilityPanel != null) {
tracerReportJPanel.add(additionalUtilityPanel);
tracerReportJPanel.add(Box.createRigidArea(dim));
}
tracerReportJPanel.add(Box.createHorizontalGlue());
tracerReportJPanel.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY, 1));
return tracerReportJPanel;
}
protected Box getObject() {
return new Box(BoxLayout.LINE_AXIS);
}
protected BoxLayout getObject() {
return new BoxLayout(new JLabel("TEST"), BoxLayout.LINE_AXIS);
}
protected BoxLayout getObject() {
return new BoxLayout(new JLabel("TEST"), BoxLayout.LINE_AXIS);
}
private JPanel getStatusBarJPanel(JTextField statusBar) {
JPanel statusBarJPanel = new JPanel();
LayoutManager layout = new BoxLayout(statusBarJPanel, BoxLayout.LINE_AXIS);
statusBarJPanel.setLayout(layout);
Dimension spacer = new Dimension(5, 16);
statusBarJPanel.add(Box.createRigidArea(spacer));
statusBarJPanel.add(statusBar);
statusBarJPanel.add(Box.createRigidArea(spacer));
statusBarJPanel.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY, 1));
return statusBarJPanel;
}
protected Box getObject() {
return new Box(BoxLayout.LINE_AXIS);
}
private JPanel getLabelJPanel(String text) {
JPanel labelJPanel = new JPanel();
LayoutManager layout = new BoxLayout(labelJPanel, BoxLayout.LINE_AXIS);
labelJPanel.setLayout(layout);
JLabel label = new JLabel(text);
int height = 30;
Dimension spacer = new Dimension(10, height);
labelJPanel.add(Box.createRigidArea(spacer));
labelJPanel.add(label);
labelJPanel.add(Box.createHorizontalGlue());
labelJPanel.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY));
return labelJPanel;
}