Java Code Examples for javax.swing.Box#setAlignmentX()

The following examples show how to use javax.swing.Box#setAlignmentX() . 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: ConnectionErrorDlg.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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);
    }
}
 
Example 2
Source File: CommonSettingsDialog.java    From megamek with GNU General Public License v2.0 6 votes vote down vote up
private JPanel createSettingsPanel(ArrayList<ArrayList<Component>> comps) {
    JPanel panel = new JPanel();
    panel.setLayout(new BorderLayout());
    Box innerpanel = new Box(BoxLayout.PAGE_AXIS);
    for (ArrayList<Component> cs : comps) {
        Box subPanel = new Box(BoxLayout.LINE_AXIS);
        for (Component c : cs) {
            if (c instanceof JLabel) {
                subPanel.add(Box.createRigidArea(LABEL_SPACER));
                subPanel.add(c);
                subPanel.add(Box.createRigidArea(LABEL_SPACER));
            } else {
                subPanel.add(c);    
            }
        }
        subPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
        innerpanel.add(subPanel);
    }
    innerpanel.add(Box.createVerticalGlue());
    innerpanel.setBorder(new EmptyBorder(10,10,10,10));
    panel.add(innerpanel,BorderLayout.PAGE_START);
    return panel;
}
 
Example 3
Source File: Operation.java    From cstc with GNU General Public License v3.0 5 votes vote down vote up
protected void addUIElement(String caption, Component comp, boolean notifyChange) {
	comp.setCursor(Cursor.getDefaultCursor());

	Box box = Box.createHorizontalBox();
	box.setAlignmentX(Component.LEFT_ALIGNMENT);
	if (comp instanceof JCheckBox) {
		comp.setBackground(new Color(0, 0, 0, 0));
	}
	JLabel lbl = new JLabel(caption);
	box.add(lbl);
	box.add(Box.createHorizontalStrut(10));
	box.add(comp);
	this.contentBox.add(box);
	this.contentBox.add(Box.createVerticalStrut(10));
	this.uiElements.put(caption, comp);

	if (notifyChange) {
		if (notifyChangeListener == null) {
			notifyChangeListener = new NotifyChangeListener();
		}

		if (comp instanceof JTextField) {
			((JTextField) comp).getDocument().addDocumentListener(notifyChangeListener);
		} else if (comp instanceof JSpinner) {
			((JSpinner) comp).addChangeListener(notifyChangeListener);
		} else if (comp instanceof JComboBox) {
			((JComboBox<?>) comp).addActionListener(notifyChangeListener);
		} else if (comp instanceof VariableTextArea) {
			((VariableTextArea) comp).addDocumentListener(notifyChangeListener);
		} else if (comp instanceof JCheckBox) {
			((JCheckBox) comp).addActionListener(notifyChangeListener);
		} else if (comp instanceof FormatTextField) {
			((FormatTextField) comp).addDocumentListener(notifyChangeListener);
		} else {
			Logger.getInstance().err("could not add a default change listener for " + comp.getClass());
		}
	}
}
 
Example 4
Source File: UiUtil.java    From intellij with Apache License 2.0 5 votes vote down vote up
/** Puts all the given components in order in a box, aligned left. */
public static Box createBox(Iterable<? extends Component> components) {
  Box box = Box.createVerticalBox();
  box.setAlignmentX(0);
  for (Component component : components) {
    if (component instanceof JComponent) {
      ((JComponent) component).setAlignmentX(0);
    }
    box.add(component);
  }
  return box;
}
 
Example 5
Source File: AboutDialog.java    From collect-earth with MIT License 5 votes vote down vote up
public AboutDialog(JFrame parent, String title) {
	super(parent, title, true);

	UpdateIniUtils updateIniUtils = new UpdateIniUtils();
	String buildDate = updateIniUtils.convertToDate(getBuild());
	
    Box b = Box.createVerticalBox();
    b.setAlignmentX(CENTER_ALIGNMENT);
    b.add(Box.createGlue());
    b.add(new JLabel("Collect Earth v. " + getVersion() + " ( built " + buildDate + ") ")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    b.add(new JLabel("By Open Foris Initiative")); //$NON-NLS-1$
    JLabel comp = new JLabel("<html>" + Messages.getString("AboutDialog.5") + "</html>"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    JLabel comp2 = new JLabel("<html><a href='https://github.com/openforis/collect-earth/blob/master/collect-earth/CHANGELOG.md'>CHECK THE CHANGE LOG</a></html>");
    if (isBrowsingSupported()) {
        makeLinkable(comp, new LinkMouseListener( "http://www.openforis.org" ));
        makeLinkable(comp2, new LinkMouseListener( "https://github.com/openforis/collect-earth/blob/master/collect-earth/CHANGELOG.md" ));
    }
	b.add(comp);
	b.add(comp2);
    b.add(Box.createGlue());
    getContentPane().add(b, "Center"); //$NON-NLS-1$

    JPanel p2 = new JPanel();
    JButton ok = new JButton(Messages.getString("AboutDialog.8")); //$NON-NLS-1$
    p2.add(ok);
    getContentPane().add(p2, "South"); //$NON-NLS-1$

    ok.addActionListener( e -> setVisible(false) );

    setSize(380, 150);
}
 
Example 6
Source File: TableEditor.java    From jdal with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new Box with table and actions buttons
 * @return a new Box
 */
protected Container createTablePanel() {
	table = new JTable(tableModel, tableModel.getTableColumnModel());
	table.setRowHeight(22);
	table.setAutoCreateRowSorter(true);
	tableModel.addTableModelListener(this);
	JScrollPane scroll = new JScrollPane(table);
	scroll.setAlignmentX(Container.LEFT_ALIGNMENT);
	Box box = Box.createVerticalBox();
	JButton addButton = new JButton(new AddAction());
	JButton deleteButton = new JButton(new DeleteAction());
	JButton saveButton = new JButton(new SaveAction());
	JButton refreshButton = new JButton(new RefreshAction());
	Box buttonBox = Box.createHorizontalBox();
	buttonBox.add(addButton);
	buttonBox.add(Box.createHorizontalStrut(5));
	buttonBox.add(deleteButton);
	buttonBox.add(Box.createHorizontalStrut(5));
	buttonBox.add(saveButton);
	buttonBox.add(Box.createHorizontalStrut(5));
	buttonBox.add(refreshButton);
	buttonBox.setAlignmentX(Container.LEFT_ALIGNMENT);
	buttonBox.setMaximumSize(new Dimension(Short.MAX_VALUE, 25));
	box.add(buttonBox);
	box.add(Box.createVerticalStrut(5));
	box.add(scroll);
	return box;
}
 
Example 7
Source File: TablePanel.java    From jdal with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new Component with FilterView.
 * @return new Component.
 */
private Component createFilterBox() {
	Box header = Box.createVerticalBox();
	
	if (filterView != null) {
		header.add(Box.createVerticalStrut(10));
		filterView.refresh();
		header.add(filterView.getPanel());
	}
	
	header.setAlignmentX(Container.LEFT_ALIGNMENT);

	return header;
}
 
Example 8
Source File: TransitionDialog.java    From SikuliX1 with MIT License 4 votes vote down vote up
void init(String text){

      setBackground(Color.yellow);
      setForeground(Color.black);

      JPanel content = new JPanel();
      content.setLayout(new BoxLayout(content, BoxLayout.Y_AXIS));
      add(content);

      textPane = new TextPane();
      textPane.setText(text);
      textPane.setBorder(BorderFactory.createEmptyBorder(3, 5, 3, 5));

      Color darkyellow = new Color(238,185,57);

      titleBar = new JLabel();
      titleBar.setFont(new Font("sansserif", Font.BOLD, 14));
      titleBar.setBackground(darkyellow);
      titleBar.setOpaque(true);
      titleBar.setBorder(BorderFactory.createEmptyBorder(5, 5, 3, 5));
      titleBar.setSize(titleBar.getPreferredSize());
      titleBar.setVisible(false);

      buttons = new Box(BoxLayout.X_AXIS);
      defaultButton = new Button("Close");
      buttons.add(defaultButton);
      buttons.setBorder(BorderFactory.createEmptyBorder(15,5,5,5));

      content.add(titleBar);
      content.add(textPane);
      content.add(buttons);

      // this allows the title bar to take the whole width of the dialog box
      titleBar.setMaximumSize(new Dimension(Integer.MAX_VALUE,Integer.MAX_VALUE));
      buttons.setMaximumSize(new Dimension(Integer.MAX_VALUE,Integer.MAX_VALUE));
      textPane.setMaximumSize(new Dimension(Integer.MAX_VALUE,Integer.MAX_VALUE));

      // these allow all the parts to left aligned
      titleBar.setAlignmentX(Component.LEFT_ALIGNMENT);
      textPane.setAlignmentX(Component.LEFT_ALIGNMENT);
      buttons.setAlignmentX(Component.LEFT_ALIGNMENT);

      // these are meant to prevent the message box from stealing
      // focus when it's clicked, but they don't seem to work
//      setFocusableWindowState(false);
//      setFocusable(false);

      // this allows the window to be dragged to another location on the screen
      ComponentMover cm = new ComponentMover();
      cm.registerComponent(this);

      pack();
   }
 
Example 9
Source File: GameInfoDialog.java    From FancyBing with GNU General Public License v3.0 4 votes vote down vote up
private GameInfoDialog(GameInfo info)
{
    Box outerBox = Box.createVerticalBox();
    m_white = createPlayerInfo(WHITE, info);
    m_white.m_box.setAlignmentX(Component.LEFT_ALIGNMENT);
    outerBox.add(m_white.m_box);
    outerBox.add(GuiUtil.createFiller());
    m_black = createPlayerInfo(BLACK, info);
    m_black.m_box.setAlignmentX(Component.LEFT_ALIGNMENT);
    outerBox.add(m_black.m_box);
    outerBox.add(GuiUtil.createFiller());
    outerBox.add(GuiUtil.createFiller());
    Box box = Box.createHorizontalBox();
    box.setAlignmentX(Component.LEFT_ALIGNMENT);
    outerBox.add(box);
    JPanel labels =
        new JPanel(new GridLayout(0, 1, 0, GuiUtil.PAD));
    box.add(labels);
    box.add(GuiUtil.createSmallFiller());
    JPanel values =
        new JPanel(new GridLayout(0, 1, 0, GuiUtil.PAD));
    box.add(values);
    m_result = createEntry("LB_GAMEINFO_RESULT", 12,
                           info.get(StringInfo.RESULT),
                           "TT_GAMEINFO_RESULT", labels, values);
    m_date = createEntry("LB_GAMEINFO_DATE", 12,
                         info.get(StringInfo.DATE),
                         "TT_GAMEINFO_DATE", labels, values);
    m_rules = createEntry("LB_GAMEINFO_RULES", 12,
                          info.get(StringInfo.RULES),
                          "TT_GAMEINFO_RULES", labels, values);
    String komi = "";
    if (info.getKomi() != null)
        komi = info.getKomi().toString();
    m_komi = createEntry("LB_GAMEINFO_KOMI", 12, komi,
                         "TT_GAMEINFO_KOMI",
                         labels, values);
    createTime(info.getTimeSettings(), labels, values);
    setMessage(outerBox);
    setOptionType(OK_CANCEL_OPTION);
}
 
Example 10
Source File: GameInfoDialog.java    From petscii-bbs with Mozilla Public License 2.0 4 votes vote down vote up
private JComponent createInfoPanel(Resources resources) {
  
  StoryMetadata storyinfo = resources.getMetadata().getStoryInfo();
  Box infopanel = Box.createVerticalBox();
  infopanel.setBorder(BorderFactory.createEmptyBorder(3, 5, 3, 5));
  JComponent panel = infopanel;
  
  // in case cover art is available, stack it into the info panel
  int coverartnum = getCoverartNum(resources);    
  if (coverartnum > 0 && resources.getImages().getNumResources() > 0) {

    Box wholepanel = Box.createHorizontalBox();
    wholepanel.add(createPicturePanel(resources, coverartnum));
    wholepanel.add(infopanel);
    panel = wholepanel;
  }
  
  infopanel.setAlignmentX(Component.LEFT_ALIGNMENT);
  infopanel.setPreferredSize(new Dimension(STD_WIDTH, 400));
  
  List<JLabel> labels = new ArrayList<JLabel>();
  labels.add(new JLabel(storyinfo.getTitle()));
  
  if (storyinfo.getHeadline() != null) {
    
    labels.add(new JLabel(storyinfo.getHeadline()));
  }
    
  labels.add(new JLabel(storyinfo.getAuthor() + " ("
      + storyinfo.getYear() + ")"));
      
  for (JLabel label : labels) {
    
    infopanel.add(label);
    label.setAlignmentX(Component.LEFT_ALIGNMENT);
    
    // Ensure that the label fonts are all bold
    label.setFont(label.getFont().deriveFont(Font.BOLD));
  }
  
  infopanel.add(Box.createVerticalStrut(6));
  
  JTextArea descarea = new JTextArea(storyinfo.getDescription());    
  descarea.setLineWrap(true);
  descarea.setWrapStyleWord(true);
  descarea.setEditable(false);
  Insets margins = new Insets(3, 3, 3, 3);
  descarea.setMargin(margins);
  descarea.setFont(labels.get(0).getFont().deriveFont(Font.PLAIN));
  
  JScrollPane spane = new JScrollPane(descarea);
  spane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
  spane.setPreferredSize(new Dimension(STD_WIDTH, 200));
  spane.setAlignmentX(Component.LEFT_ALIGNMENT);
  infopanel.add(spane);
  return panel;
}
 
Example 11
Source File: SettlementTransparentPanel.java    From mars-sim with GNU General Public License v3.0 4 votes vote down vote up
public void createAndShowGUI() {

	    emptyLabel = new JLabel("  ") {
	    	@Override
	    	public Dimension getMinimumSize() {
	    		return new Dimension(50, 100);
	    	};
	    	@Override
	    	public Dimension getPreferredSize() {
	    		return new Dimension(50, 100);
	    	};
	    };

        buildLabelPane();
        buildSettlementNameComboBox();
        buildInfoP();
        buildrenameBtn();
        buildZoomSlider();
        buildButtonPane();

		nameBtnPane = new JPanel(new FlowLayout());
		nameBtnPane.setBackground(new Color(0,0,0));
        nameBtnPane.setOpaque(false);

      	nameBtnPane.add(infoP);
       	nameBtnPane.add(renameP);
       	nameBtnPane.add(new JLabel(""));

		settlementPanel = new JPanel();//new BorderLayout());
		settlementPanel.setBackground(new Color(0,0,0,128));
		settlementPanel.setOpaque(false);
		settlementPanel.add(settlementListBox);//, BorderLayout.CENTER);

		Box box = new Box(BoxLayout.Y_AXIS);
	    box.add(Box.createVerticalGlue());
	    box.setAlignmentX(JComponent.CENTER_ALIGNMENT);
	    //box.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY));
	    box.add(Box.createVerticalGlue());
		box.setBackground(new Color(0,0,0,128));
		box.setOpaque(false);
	    box.add(settlementPanel);
	    box.add(nameBtnPane);

	    mapPanel.add(box, BorderLayout.NORTH);

	    controlCenterPane = new JPanel(new FlowLayout(FlowLayout.CENTER));
	    controlCenterPane.setBackground(new Color(0,0,0,128));//,0));
	    controlCenterPane.setOpaque(false);
        controlCenterPane.setPreferredSize(new Dimension(50, 200));
        controlCenterPane.setSize(new Dimension(50, 200));
        controlCenterPane.add(zoomSlider);

	    controlPane = new JPanel(new BorderLayout());//GridLayout(2,1,10,2));
	    controlPane.setBackground(new Color(0,0,0,128));//,0));
		controlPane.setOpaque(false);
       	controlPane.add(buttonPane, BorderLayout.NORTH);
	    controlPane.add(labelPane, BorderLayout.SOUTH);
       	controlPane.add(controlCenterPane, BorderLayout.CENTER);

	    eastPane = new JPanel(new BorderLayout());//GridLayout(3,1,10,2));
		eastPane.setBackground(new Color(0,0,0,15));
		eastPane.setBackground(new Color(0,0,0));//,0));
		eastPane.setOpaque(false);
        eastPane.add(emptyLabel, BorderLayout.EAST);
        eastPane.add(emptyLabel, BorderLayout.WEST);
        eastPane.add(emptyLabel, BorderLayout.NORTH);
        eastPane.add(emptyLabel, BorderLayout.SOUTH);
        eastPane.add(controlPane, BorderLayout.CENTER);

        mapPanel.add(eastPane, BorderLayout.EAST);
        // Make panel drag-able
//  	ComponentMover cmZoom = new ComponentMover(zoomPane);
		//cmZoom.registerComponent(rightPane);
//		cmZoom.registerComponent(zoomPane);
        mapPanel.setVisible(true);
    }
 
Example 12
Source File: ProjectCalendarOptionPageProvider.java    From ganttproject with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Component buildPageComponent() {
  final GanttLanguage i18n = GanttLanguage.getInstance();
  final Box result = Box.createVerticalBox();

  myWeekendsPanel = new WeekendsSettingsPanel(getProject(), getUiFacade());
  myWeekendsPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
  myWeekendsPanel.initialize();
  result.add(myWeekendsPanel);

  result.add(Box.createVerticalStrut(15));

  myProjectStart = getProject().getTaskManager().getProjectStart();
  myProjectStartOption = new DefaultDateOption("project.startDate", myProjectStart) {
    private TimeDuration getMoveDuration() {
      return getProject().getTaskManager().createLength(getProject().getTimeUnitStack().getDefaultTimeUnit(),
          getInitialValue(), getValue());
    }

    @Override
    public void setValue(Date value) {
      super.setValue(value);
      TimeDuration moveDuration = getMoveDuration();
      if (moveDuration.getLength() != 0) {
        updateMoveOptions(moveDuration);
      }
    }

    @Override
    public void commit() {
      super.commit();
      if (!isChanged()) {
        return;
      }
      try {
        moveProject(getMoveDuration());
      } catch (AlgorithmException e) {
        getUiFacade().showErrorDialog(e);
      }
    }
  };

  myMoveOptionsPanel = Box.createVerticalBox();
  myMoveOptionsPanel.setAlignmentX(Component.LEFT_ALIGNMENT);

  Box dateComponent = Box.createHorizontalBox();
  OptionsPageBuilder builder = new OptionsPageBuilder();
  dateComponent.add(new JLabel(i18n.getText(builder.getI18N().getCanonicalOptionLabelKey(myProjectStartOption))));
  dateComponent.add(Box.createHorizontalStrut(3));
  dateComponent.add(builder.createDateComponent(myProjectStartOption));
  dateComponent.setAlignmentX(Component.LEFT_ALIGNMENT);
  myMoveOptionsPanel.add(dateComponent);
  myMoveOptionsPanel.add(Box.createVerticalStrut(5));

  myMoveStrategyPanelWrapper = new JPanel(new BorderLayout()) {
    @Override
    public void paint(Graphics g) {
      if (isEnabled()) {
        super.paint(g);
        return;
      }
      final BufferedImage buf = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_RGB);
      super.paint(buf.getGraphics());
      final float[] my_kernel = { 0.0625f, 0.125f, 0.0625f, 0.125f, 0.25f, 0.125f, 0.0625f, 0.125f, 0.0625f };
      final ConvolveOp op = new ConvolveOp(new Kernel(3, 3, my_kernel), ConvolveOp.EDGE_NO_OP, null);
      Image img = op.filter(buf, null);
      g.drawImage(img, 0, 0, null);
    }
  };
  myMoveStrategyPanelWrapper.setAlignmentX(Component.LEFT_ALIGNMENT);

  myMoveAllTasks = new JRadioButton(i18n.getText("project.calendar.moveAll.label"));
  myMoveAllTasks.setAlignmentX(Component.LEFT_ALIGNMENT);

  myMoveStartingTasks = new JRadioButton(MessageFormat.format(i18n.getText("project.calendar.moveSome.label"),
      i18n.formatDate(CalendarFactory.createGanttCalendar(myProjectStart))));
  myMoveStartingTasks.setAlignmentX(Component.LEFT_ALIGNMENT);

  ButtonGroup moveGroup = new ButtonGroup();
  moveGroup.add(myMoveAllTasks);
  moveGroup.add(myMoveStartingTasks);
  moveGroup.setSelected(myMoveAllTasks.getModel(), true);

  Box moveStrategyPanel = Box.createVerticalBox();
  myMoveDurationLabel = new JLabel();
  myMoveDurationLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
  moveStrategyPanel.add(myMoveDurationLabel);
  moveStrategyPanel.add(myMoveAllTasks);
  moveStrategyPanel.add(myMoveStartingTasks);

  myMoveStrategyPanelWrapper.add(moveStrategyPanel, BorderLayout.CENTER);
  myMoveOptionsPanel.add(Box.createVerticalStrut(3));
  myMoveOptionsPanel.add(myMoveStrategyPanelWrapper);

  UIUtil.createTitle(myMoveOptionsPanel, i18n.getText("project.calendar.move.title"));
  result.add(myMoveOptionsPanel);

  updateMoveOptions(getProject().getTaskManager().createLength(0));
  return OptionPageProviderBase.wrapContentComponent(result, getCanonicalPageTitle(), null);
}