Java Code Examples for java.awt.FlowLayout#setAlignment()

The following examples show how to use java.awt.FlowLayout#setAlignment() . 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: JPlagCreator.java    From jplag with GNU General Public License v3.0 6 votes vote down vote up
/**
 * If width or height is not greater than 0, preferred size will not be set
 */
public static JPanel createPanel(int width, int height, int vGap, int hGap, int alignment) {
	FlowLayout flowLayout1 = new FlowLayout();
	JPanel controlPanel = new JPanel();

	controlPanel.setLayout(flowLayout1);
	flowLayout1.setAlignment(alignment);
	if (width > 0 && height > 0)
		controlPanel.setPreferredSize(new java.awt.Dimension(width, height));

	controlPanel.setBackground(JPlagCreator.SYSTEMCOLOR);
	controlPanel.setBorder(JPlagCreator.LINE);
	flowLayout1.setVgap(vGap);
	flowLayout1.setHgap(hGap);
	return controlPanel;
}
 
Example 2
Source File: ShapeBoard.java    From audiveris with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Build the panel of shapes for a given set.
 *
 * @param set the given set of shapes
 * @return the panel of shapes for the provided set
 */
private Panel buildShapesPanel (ShapeSet set)
{
    Panel panel = new Panel();
    panel.setNoInsets();
    panel.setPreferredSize(new Dimension(BOARD_WIDTH, getSetHeight(set)));

    FlowLayout layout = new FlowLayout();
    layout.setAlignment(FlowLayout.LEADING);
    panel.setLayout(layout);

    // Button to close this shapes panel and return to sets panel
    JButton close = new JButton(set.getName());
    close.addActionListener(closeListener);
    close.setToolTipText("Back to shape sets");
    close.setBorderPainted(false);
    panel.add(close);
    panel.addKeyListener(keyListener);

    // One button per shape
    addButtons(panel, set.getSortedShapes());

    return panel;
}
 
Example 3
Source File: TurnsPanel.java    From MtgDesktopCompanion with GNU General Public License v3.0 6 votes vote down vote up
public TurnsPanel() {
	FlowLayout flowLayout = (FlowLayout) getLayout();
	flowLayout.setVgap(1);
	flowLayout.setHgap(1);
	flowLayout.setAlignment(FlowLayout.LEFT);
	lblTurnNumber = new JLabel("Turn " + GameManager.getInstance().getTurns().size());
	add(lblTurnNumber);

	add(new JButton(new UntapPhase()));
	add(new JButton(new UpkeepPhase()));
	add(new JButton(new DrawPhase()));
	add(new JButton(new MainPhase(1)));
	add(new JButton(new CombatPhase()));
	add(new JButton(new AttackPhase()));
	add(new JButton(new BlockPhase()));
	add(new JButton(new DamagePhase()));
	add(new JButton(new EndCombatPhase()));
	add(new JButton(new MainPhase(2)));
	add(new JButton(new EndPhase()));
	add(new JButton(new CleanUpPhase()));
	add(new JButton(new EndTurnPhase()));
}
 
Example 4
Source File: JLabelledValue.java    From mpxj with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Constructor.
 *
 * @param label fixed label text
 */
public JLabelledValue(String label)
{
   FlowLayout flowLayout = (FlowLayout) getLayout();
   flowLayout.setAlignment(FlowLayout.LEFT);
   flowLayout.setVgap(0);
   flowLayout.setHgap(0);
   JLabel textLabel = new JLabel(label);
   textLabel.setFont(new Font("Tahoma", Font.BOLD, 11));
   textLabel.setPreferredSize(new Dimension(70, 14));
   add(textLabel);

   m_valueLabel = new JLabel("");
   m_valueLabel.setPreferredSize(new Dimension(80, 14));
   add(m_valueLabel);
}
 
Example 5
Source File: JPlagCreator.java    From jplag with GNU General Public License v3.0 6 votes vote down vote up
public static JPanel createPanel(String title, int width, int height, int vGap, int hGap, int alignment, int type) {
	FlowLayout flowLayout1 = new FlowLayout();
	JPanel controlPanel = new JPanel();

	controlPanel.setLayout(flowLayout1);
	flowLayout1.setAlignment(alignment);
	controlPanel.setPreferredSize(new java.awt.Dimension(width, height));

	controlPanel.setBackground(JPlagCreator.SYSTEMCOLOR);
	if (type == WITH_LINEBORDER)
		controlPanel.setBorder(JPlagCreator.LINE);
	if (type == WITH_TITLEBORDER)
		controlPanel.setBorder(JPlagCreator.titleBorder(title, Color.BLACK, Color.BLACK));
	flowLayout1.setVgap(vGap);
	flowLayout1.setHgap(hGap);
	return controlPanel;
}
 
Example 6
Source File: Query.java    From OpenDA with GNU Lesser General Public License v3.0 5 votes vote down vote up
/** Create a bank of radio buttons.  A radio button provides a list of
 *  choices, only one of which may be chosen at a time.
 *  @param name The name used to identify the entry (when calling get).
 *  @param label The label to attach to the entry.
 *  @param values The list of possible choices.
 *  @param defaultValue Default value.
 */
public void addRadioButtons(
    String name,
    String label,
    String[] values,
    String defaultValue) {
    JLabel lbl = new JLabel(label + ": ");
    lbl.setBackground(_background);
    FlowLayout flow = new FlowLayout();
    flow.setAlignment(FlowLayout.LEFT);

    // This must be a JPanel, not a Panel, or the scroll bars won't work.
    JPanel buttonPanel = new JPanel(flow);

    ButtonGroup group = new ButtonGroup();
    QueryActionListener listener = new QueryActionListener(name);

    // Regrettably, ButtonGroup provides no method to find out
    // which button is selected, so we have to go through a
    // song and dance here...
    JRadioButton[] buttons = new JRadioButton[values.length];
    for (int i = 0; i < values.length; i++) {
        JRadioButton checkbox = new JRadioButton(values[i]);
        buttons[i] = checkbox;
        checkbox.setBackground(_background);
        // The following (essentially) undocumented method does nothing...
        // checkbox.setContentAreaFilled(true);
        checkbox.setOpaque(false);
        if (values[i].equals(defaultValue)) {
            checkbox.setSelected(true);
        }
        group.add(checkbox);
        buttonPanel.add(checkbox);
        // Add the listener last so that there is no notification
        // of the first value.
        checkbox.addActionListener(listener);
    }
    _addPair(name, lbl, buttonPanel, buttons);
}
 
Example 7
Source File: ShapeBoard.java    From libreveris with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Define the panel of shapes for a given range.
 *
 * @param range the given range of shapes
 * @return the panel of shapes for the provided range
 */
private Panel defineShapesPanel (ShapeSet range)
{
    Panel panel = new Panel();
    panel.setNoInsets();
    panel.setPreferredSize(new Dimension(BOARD_WIDTH, heights.get(range)));

    FlowLayout layout = new FlowLayout();
    layout.setAlignment(FlowLayout.LEADING);
    panel.setLayout(layout);

    // Button to close this shapes panel and return to ranges panel
    JButton close = new JButton(range.getName());
    close.addActionListener(closeListener);
    close.setToolTipText("Back to ranges");
    close.setBorderPainted(false);
    panel.add(close);

    // One button per shape
    for (Shape shape : range.getSortedShapes()) {
        ShapeButton button = new ShapeButton(shape);
        button.addMouseListener(dropAdapter); // For DnD transfer
        button.addMouseListener(mouseListener); // For double-click
        button.addMouseMotionListener(motionAdapter); // For dragging
        panel.add(button);
    }

    return panel;
}
 
Example 8
Source File: ShapeBoard.java    From libreveris with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Define the global panel of ranges.
 *
 * @return the global panel of ranges
 */
private Panel defineRangesPanel ()
{
    Panel panel = new Panel();
    panel.setNoInsets();
    panel.setPreferredSize(new Dimension(BOARD_WIDTH, 180));

    FlowLayout layout = new FlowLayout();
    layout.setAlignment(FlowLayout.LEADING);
    panel.setLayout(layout);

    for (ShapeSet range : ShapeSet.getShapeSets()) {
        Shape rep = range.getRep();

        if (rep != null) {
            JButton button = new JButton();
            button.setIcon(rep.getDecoratedSymbol());
            button.setName(range.getName());
            button.addActionListener(rangeListener);
            button.setToolTipText(range.getName());
            button.setBorderPainted(false);
            panel.add(button);
        }
    }

    return panel;
}
 
Example 9
Source File: JChoice.java    From gate-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Creates a FastChoice with the given data model.
 */
public JChoice(ComboBoxModel<E> model) {
  layout = new FlowLayout();
  layout.setHgap(0);
  layout.setVgap(0);
  layout.setAlignment(FlowLayout.LEFT);
  setLayout(layout);
  this.model = model;
  //by default nothing is selected
  setSelectedItem(null);
  initLocalData();
  buildGui();
}
 
Example 10
Source File: ShapeBoard.java    From audiveris with GNU Affero General Public License v3.0 5 votes vote down vote up
public ShapeHistory ()
{
    panel.setNoInsets();
    panel.setPreferredSize(new Dimension(BOARD_WIDTH, 80));
    panel.setVisible(false);

    FlowLayout layout = new FlowLayout();
    layout.setAlignment(FlowLayout.LEADING);
    panel.setLayout(layout);
}
 
Example 11
Source File: ListRenderer.java    From PandaTvDanMu with MIT License 5 votes vote down vote up
public ListRenderer() {
	userName = new JLabel();
	symbolAfterUserName = new JLabel();
	message = new JLabel();
	giftNumber = new JLabel();
	giftUnit = new JLabel();
	giftName = new JLabel();
	
	FlowLayout layout=new FlowLayout();
	setLayout(layout);
	layout.setAlignment(FlowLayout.LEFT);
	
	add(userName);
	add(symbolAfterUserName);
	add(message);
	add(giftNumber);
	add(giftUnit);
	add(giftName);
	
	
	
	userName.setForeground(new Color(0x6D40DB));
	symbolAfterUserName.setForeground(Color.yellow);
	message.setForeground(Color.white);
	giftNumber.setForeground(new Color(0xFF3C61));
	giftUnit.setForeground(Color.white);
	giftName.setForeground(new Color(0x24B073));
	
	userName.setFont(new Font("微软雅黑 ", Font.PLAIN, 12));
	symbolAfterUserName.setFont(new Font("微软雅黑 ", Font.PLAIN, 12));
	message.setFont(new Font("微软雅黑 ", Font.PLAIN, 12));
	giftNumber.setFont(new Font("微软雅黑 ", Font.PLAIN, 12));
	giftUnit.setFont(new Font("微软雅黑 ", Font.PLAIN, 12));
	giftName.setFont(new Font("微软雅黑 ", Font.PLAIN, 12));
	
	setOpaque(false);
}
 
Example 12
Source File: MultiSpectraVisualizerWindow.java    From mzmine2 with GNU General Public License v2.0 4 votes vote down vote up
public MultiSpectraVisualizerWindow(PeakListRow row, RawDataFile raw) {
  setBackground(Color.WHITE);
  setExtendedState(JFrame.MAXIMIZED_BOTH);
  setMinimumSize(new Dimension(800, 600));
  setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
  getContentPane().setLayout(new BorderLayout());

  pnGrid = new JPanel();
  // any number of rows
  pnGrid.setLayout(new GridLayout(0, 1, 0, 25));
  pnGrid.setAutoscrolls(true);

  JScrollPane scrollPane = new JScrollPane(pnGrid);
  scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
  scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
  getContentPane().add(scrollPane, BorderLayout.CENTER);

  JPanel pnMenu = new JPanel();
  FlowLayout fl_pnMenu = (FlowLayout) pnMenu.getLayout();
  fl_pnMenu.setVgap(0);
  fl_pnMenu.setAlignment(FlowLayout.LEFT);
  getContentPane().add(pnMenu, BorderLayout.NORTH);

  JButton nextRaw = new JButton("next");
  nextRaw.addActionListener(e -> nextRaw());
  JButton prevRaw = new JButton("prev");
  prevRaw.addActionListener(e -> prevRaw());
  pnMenu.add(prevRaw);
  pnMenu.add(nextRaw);

  lbRaw = new JLabel();
  pnMenu.add(lbRaw);

  JLabel lbRawTotalWithFragmentation = new JLabel();
  pnMenu.add(lbRaw);

  int n = 0;
  for (Feature f : row.getPeaks()) {
    if (f.getMostIntenseFragmentScanNumber() > 0)
      n++;
  }
  lbRawTotalWithFragmentation.setText("(total raw:" + n + ")");

  // add charts
  setData(row, raw);

  setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
  setVisible(true);
  validate();
  repaint();
  pack();
}
 
Example 13
Source File: Option.java    From CQL with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Creates a new label/component pair. If given multiple compnents, will add
 * them to a JPanel and then set that as the component. Note that this is better
 * than putting them into a JPanel yourself: the label will be centered on the
 * first component passed-in.
 *
 * @param label      the JLabel of the option
 * @param components
 */
public Option(JLabel label, JComponent... components) {
	setLabel(label);

	if (components.length > 1) {
		JPanel panel = new JPanel();
		FlowLayout flow = (FlowLayout) panel.getLayout();

		flow.setAlignment(FlowLayout.LEFT);
		flow.setVgap(0);
		flow.setHgap(0);

		for (JComponent jc : components) {
			panel.add(jc);
		}

		JUtils.fixHeight(panel);
		setComponent(panel);
	} else {
		setComponent((components.length > 0) ? components[0] : null);
	}

	// We try to align the label with the first component (descending into
	// JPanels), by creating a border that aligns the middle of the border
	// with the middle of the first component.
	if (components.length > 0) {
		int labelOffset = -label.getPreferredSize().height;
		Component comp = components[0];

		while (comp instanceof JPanel) {
			labelOffset += 2 * (((JPanel) comp).getInsets().top);
			comp = ((JPanel) comp).getComponent(0);
		}

		if (comp != null) {
			labelOffset += comp.getPreferredSize().height;

			if (labelOffset > 0) { // Only do it if the first non-JPanel
									// component is bigger
				label.setBorder(new EmptyBorder(labelOffset / 2, 0, 0, 0));
			}
		}
	}
}
 
Example 14
Source File: DeckDetailsPanel.java    From MtgDesktopCompanion with GNU General Public License v3.0 4 votes vote down vote up
public DeckDetailsPanel() {
	GridBagLayout gridBagLayout = new GridBagLayout();
	gridBagLayout.columnWidths = new int[] { 0, 140, 0, 0, 0 };
	gridBagLayout.rowHeights = new int[] { 28, 30, 35, 0, 132, 31, 0, 0, 0, 0 };
	gridBagLayout.columnWeights = new double[] { 0.0, 0.0, 1.0, 0.0, 1.0E-4 };
	gridBagLayout.rowWeights = new double[] { 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0E-4 };
	setLayout(gridBagLayout);

	add(new JLabel(MTGControler.getInstance().getLangService().getCapitalize("DECK_NAME") + " :"), UITools.createGridBagConstraints(null, null, 1, 0));
	nameJTextField = new JTextField();
	add(nameJTextField, UITools.createGridBagConstraints(null, GridBagConstraints.HORIZONTAL, 2, 0));

	add(new JLabel(MTGControler.getInstance().getLangService().getCapitalize("CARD_LEGALITIES") + " :"), UITools.createGridBagConstraints(null, null, 1, 1));
	panelLegalities = new JPanel();
	FlowLayout flowLayout = (FlowLayout) panelLegalities.getLayout();
	flowLayout.setHgap(10);
	flowLayout.setAlignment(FlowLayout.LEFT);
	add(panelLegalities, UITools.createGridBagConstraints(null, GridBagConstraints.BOTH, 2, 1));

	add(new JLabel(MTGControler.getInstance().getLangService().getCapitalize("CARD_COLOR") + " :"), UITools.createGridBagConstraints(null, null, 1, 2));
	manaPanel = new ManaPanel();
	add(manaPanel, UITools.createGridBagConstraints(null, GridBagConstraints.BOTH, 2, 2));

	lblDate = new JLabel(MTGControler.getInstance().getLangService().getCapitalize("DATE") + " :");
	add(lblDate, UITools.createGridBagConstraints(null, null, 1, 3));

	lblDateInformation = new JLabel("");
	add(lblDateInformation, UITools.createGridBagConstraints(GridBagConstraints.WEST, null, 2, 3));

	add(new JLabel(MTGControler.getInstance().getLangService().getCapitalize("DESCRIPTION") + " :"), UITools.createGridBagConstraints(null, null, 1, 4));

	textArea = new JTextArea();
	textArea.setLineWrap(true);
	textArea.setWrapStyleWord(true);

	add(new JLabel(MTGControler.getInstance().getLangService().getCapitalize("QTY") + " :"), UITools.createGridBagConstraints(null, null, 1, 5));
	nbCardsProgress = new JProgressBar();
	nbCardsProgress.setStringPainted(true);
	add(nbCardsProgress, UITools.createGridBagConstraints(null, GridBagConstraints.HORIZONTAL, 2, 5));

	lbstd = new JLabel(" STD ");
	lbstd.setOpaque(true);
	lbstd.setBackground(Color.GREEN);
	lbmnd = new JLabel(" MDN ");
	lbmnd.setOpaque(true);
	lbmnd.setBackground(Color.GREEN);
	lbvin = new JLabel(" VIN ");
	lbvin.setOpaque(true);
	lbvin.setBackground(Color.GREEN);
	lbcmd = new JLabel(" CMD ");
	lbcmd.setOpaque(true);
	lbcmd.setBackground(Color.GREEN);
	lbLeg = new JLabel(" LEG ");
	lbLeg.setOpaque(true);
	lbLeg.setBackground(Color.GREEN);

	panelLegalities.add(lbvin);
	panelLegalities.add(lbLeg);
	panelLegalities.add(lbstd);
	panelLegalities.add(lbmnd);
	panelLegalities.add(lbcmd);

	add(new JLabel(MTGControler.getInstance().getLangService().getCapitalize("SIDEBOARD") + " :"), UITools.createGridBagConstraints(null, null, 1, 6));

	nbSideProgress = new JProgressBar();
	nbSideProgress.setMaximum(15);
	nbSideProgress.setStringPainted(true);
	add(nbSideProgress, UITools.createGridBagConstraints(null, GridBagConstraints.HORIZONTAL, 2, 6));

	add(new JScrollPane(textArea), UITools.createGridBagConstraints(null, GridBagConstraints.BOTH, 2, 4));

	add(new JLabel(MTGControler.getInstance().getLangService().getCapitalize("TAGS") + " :"), UITools.createGridBagConstraints(null, GridBagConstraints.BOTH, 1, 7));

	tagsPanel = new JTagsPanel();
	add(tagsPanel, UITools.createGridBagConstraints(GridBagConstraints.WEST, GridBagConstraints.VERTICAL, 2, 7));

	panel = new JPanel();
	add(panel, UITools.createGridBagConstraints(null, GridBagConstraints.BOTH, 2, 8));

	if (magicDeck != null) {
		mBindingGroup = initDataBindings();
	}
}
 
Example 15
Source File: MagicEditionJLabelRenderer.java    From MtgDesktopCompanion with GNU General Public License v3.0 4 votes vote down vote up
public MagicEditionJLabelRenderer() {
	FlowLayout flowLayout = new FlowLayout();
	flowLayout.setVgap(0);
	flowLayout.setAlignment(FlowLayout.LEFT);
	pane.setLayout(flowLayout);
}
 
Example 16
Source File: MagicEditionsJLabelRenderer.java    From MtgDesktopCompanion with GNU General Public License v3.0 4 votes vote down vote up
public MagicEditionsJLabelRenderer() {
	FlowLayout flowLayout = new FlowLayout();
	flowLayout.setVgap(0);
	flowLayout.setAlignment(FlowLayout.LEFT);
	pane.setLayout(flowLayout);
}
 
Example 17
Source File: ProgressPanel.java    From jplag with GNU General Public License v3.0 4 votes vote down vote up
/**
 * This method initializes this
 * 
 * @return void
 */
private void initialize() {
	FlowLayout flowLayout1 = new FlowLayout();

	this.setLayout(flowLayout1);
	packing = JPlagCreator.createLabel(Messages.getString(
           "ProgressPanel.Packing_files"), 200, 20); //$NON-NLS-1$
	sending = JPlagCreator.createLabel(Messages.getString(
           "ProgressPanel.Sending_files"), 200, 20); //$NON-NLS-1$
	waiting = JPlagCreator.createLabel(Messages.getString(
           "ProgressPanel.Waiting_in_queue"),200, 20); //$NON-NLS-1$
	parsing = JPlagCreator.createLabel(Messages.getString(
           "ProgressPanel.Parsing_files"), 200, 20); //$NON-NLS-1$
	comparing = JPlagCreator.createLabel(Messages.getString(
           "ProgressPanel.Comparing_files"), 200, 20); //$NON-NLS-1$
	loading = JPlagCreator.createLabel(Messages.getString(
           "ProgressPanel.Loading_results"), 200, 20); //$NON-NLS-1$
	loading.setBackground(Color.WHITE);

	this.setPreferredSize(new java.awt.Dimension(200, 120));

	// TODO: Upload missing file to repository!!
	packing.setIcon(new ImageIcon(getClass().getResource(
			"/atujplag/data/current.gif"))); //$NON-NLS-1$
	sending.setIcon(new ImageIcon(getClass().getResource(
			"/atujplag/data/current.gif"))); //$NON-NLS-1$
	waiting.setIcon(new ImageIcon(getClass().getResource(
			"/atujplag/data/current.gif"))); //$NON-NLS-1$
	parsing.setIcon(new ImageIcon(getClass().getResource(
			"/atujplag/data/current.gif"))); //$NON-NLS-1$
	comparing.setIcon(new ImageIcon(getClass().getResource(
			"/atujplag/data/current.gif"))); //$NON-NLS-1$
	loading.setIcon(new ImageIcon(getClass().getResource(
			"/atujplag/data/current.gif"))); //$NON-NLS-1$
	flowLayout1.setHgap(50);
	flowLayout1.setVgap(0);
	flowLayout1.setAlignment(java.awt.FlowLayout.CENTER);
	this.setBackground(JPlagCreator.SYSTEMCOLOR);
	this.add(packing);
	this.add(sending);
	this.add(waiting);
	this.add(parsing);
	this.add(comparing);
	this.add(loading);
}
 
Example 18
Source File: Query.java    From opt4j with MIT License 4 votes vote down vote up
/**
 * Create a bank of buttons that provides a list of choices, any subset of
 * which may be chosen at a time.
 * 
 * @param name
 *            The name used to identify the entry (when calling get).
 * @param label
 *            The label to attach to the entry.
 * @param values
 *            The list of possible choices.
 * @param initiallySelected
 *            The initially selected choices, or null to indicate that none
 *            are selected.
 */
public void addSelectButtons(String name, String label, String[] values, Set<String> initiallySelected) {
	JLabel lbl = new JLabel(label + ": ");
	lbl.setBackground(_background);

	FlowLayout flow = new FlowLayout();
	flow.setAlignment(FlowLayout.LEFT);

	// This must be a JPanel, not a Panel, or the scroll bars won't work.
	JPanel buttonPanel = new JPanel(flow);

	QueryActionListener listener = new QueryActionListener(name);

	if (initiallySelected == null) {
		initiallySelected = new HashSet<String>();
	}

	JRadioButton[] buttons = new JRadioButton[values.length];

	for (int i = 0; i < values.length; i++) {
		JRadioButton checkbox = new JRadioButton(values[i]);
		buttons[i] = checkbox;
		checkbox.setBackground(_background);

		// The following (essentially) undocumented method does nothing...
		// checkbox.setContentAreaFilled(true);
		checkbox.setOpaque(false);

		if (initiallySelected.contains(values[i])) {
			checkbox.setSelected(true);
		}

		buttonPanel.add(checkbox);

		// Add the listener last so that there is no notification
		// of the first value.
		checkbox.addActionListener(listener);
	}

	_addPair(name, lbl, buttonPanel, buttons);
}
 
Example 19
Source File: Query.java    From opt4j with MIT License 4 votes vote down vote up
/**
 * Create a bank of radio buttons. A radio button provides a list of
 * choices, only one of which may be chosen at a time.
 * 
 * @param name
 *            The name used to identify the entry (when calling get).
 * @param label
 *            The label to attach to the entry.
 * @param values
 *            The list of possible choices.
 * @param defaultValue
 *            Default value.
 */
public void addRadioButtons(String name, String label, String[] values, String defaultValue) {
	JLabel lbl = new JLabel(label + ": ");
	lbl.setBackground(_background);

	FlowLayout flow = new FlowLayout();
	flow.setAlignment(FlowLayout.LEFT);

	// This must be a JPanel, not a Panel, or the scroll bars won't work.
	JPanel buttonPanel = new JPanel(flow);

	ButtonGroup group = new ButtonGroup();
	QueryActionListener listener = new QueryActionListener(name);

	// Regrettably, ButtonGroup provides no method to find out
	// which button is selected, so we have to go through a
	// song and dance here...
	JRadioButton[] buttons = new JRadioButton[values.length];

	for (int i = 0; i < values.length; i++) {
		JRadioButton checkbox = new JRadioButton(values[i]);
		buttons[i] = checkbox;
		checkbox.setBackground(_background);

		// The following (essentially) undocumented method does nothing...
		// checkbox.setContentAreaFilled(true);
		checkbox.setOpaque(false);

		if (values[i].equals(defaultValue)) {
			checkbox.setSelected(true);
		}

		group.add(checkbox);
		buttonPanel.add(checkbox);

		// Add the listener last so that there is no notification
		// of the first value.
		checkbox.addActionListener(listener);
	}

	_addPair(name, lbl, buttonPanel, buttons);
}
 
Example 20
Source File: MultiSpectraVisualizerWindow.java    From mzmine3 with GNU General Public License v2.0 4 votes vote down vote up
public MultiSpectraVisualizerWindow(PeakListRow row, RawDataFile raw) {
  setBackground(Color.WHITE);
  setExtendedState(JFrame.MAXIMIZED_BOTH);
  setMinimumSize(new Dimension(800, 600));
  setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
  getContentPane().setLayout(new BorderLayout());

  pnGrid = new JPanel();
  // any number of rows
  pnGrid.setLayout(new GridLayout(0, 1, 0, 25));
  pnGrid.setAutoscrolls(true);

  JScrollPane scrollPane = new JScrollPane(pnGrid);
  scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
  scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
  getContentPane().add(scrollPane, BorderLayout.CENTER);

  JPanel pnMenu = new JPanel();
  FlowLayout fl_pnMenu = (FlowLayout) pnMenu.getLayout();
  fl_pnMenu.setVgap(0);
  fl_pnMenu.setAlignment(FlowLayout.LEFT);
  getContentPane().add(pnMenu, BorderLayout.NORTH);

  JButton nextRaw = new JButton("next");
  nextRaw.addActionListener(e -> nextRaw());
  JButton prevRaw = new JButton("prev");
  prevRaw.addActionListener(e -> prevRaw());
  pnMenu.add(prevRaw);
  pnMenu.add(nextRaw);

  lbRaw = new JLabel();
  pnMenu.add(lbRaw);

  JLabel lbRawTotalWithFragmentation = new JLabel();
  pnMenu.add(lbRaw);

  int n = 0;
  for (Feature f : row.getPeaks()) {
    if (f.getMostIntenseFragmentScanNumber() > 0)
      n++;
  }
  lbRawTotalWithFragmentation.setText("(total raw:" + n + ")");

  // add charts
  setData(row, raw);

  setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
  setVisible(true);
  validate();
  repaint();
  pack();
}