Java Code Examples for java.awt.GridBagLayout#setConstraints()

The following examples show how to use java.awt.GridBagLayout#setConstraints() . 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: PolicyTool.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Add a component to the PolicyTool window
 */
void addNewComponent(Container container, JComponent component,
    int index, int gridx, int gridy, int gridwidth, int gridheight,
    double weightx, double weighty, int fill, Insets is) {

    if (container instanceof JFrame) {
        container = ((JFrame)container).getContentPane();
    } else if (container instanceof JDialog) {
        container = ((JDialog)container).getContentPane();
    }

    // add the component at the specified gridbag index
    container.add(component, index);

    // set the constraints
    GridBagLayout gbl = (GridBagLayout)container.getLayout();
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.gridx = gridx;
    gbc.gridy = gridy;
    gbc.gridwidth = gridwidth;
    gbc.gridheight = gridheight;
    gbc.weightx = weightx;
    gbc.weighty = weighty;
    gbc.fill = fill;
    if (is != null) gbc.insets = is;
    gbl.setConstraints(component, gbc);
}
 
Example 2
Source File: PropertiesOpen.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Inits the subcomponents. Sets layout for this top component and adds {@code BundleEditPanel} to it. 
 * @see BundleEditPanel */
private void initComponents() {
    GridBagLayout gridbag = new GridBagLayout();
    setLayout(gridbag);

    GridBagConstraints c = new GridBagConstraints();
    c.fill = GridBagConstraints.BOTH;
    c.weightx = 1.0;
    c.weighty = 1.0;
    c.gridwidth = GridBagConstraints.REMAINDER;
    JPanel panel = new BundleEditPanel(bundleStructure, new PropertiesTableModel(bundleStructure));
    gridbag.setConstraints(panel, c);
    add(panel);
}
 
Example 3
Source File: ServiceDialog.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sets the constraints for the GridBagLayout and adds the Component
 * to the given Container
 */
private static void addToGB(Component comp, Container cont,
                            GridBagLayout gridbag,
                            GridBagConstraints constraints)
{
    gridbag.setConstraints(comp, constraints);
    cont.add(comp);
}
 
Example 4
Source File: ServiceDialog.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sets the constraints for the GridBagLayout and adds the Component
 * to the given Container
 */
private static void addToGB(Component comp, Container cont,
                            GridBagLayout gridbag,
                            GridBagConstraints constraints)
{
    gridbag.setConstraints(comp, constraints);
    cont.add(comp);
}
 
Example 5
Source File: PolicyTool.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Add a component to the PolicyTool window
 */
void addNewComponent(Container container, JComponent component,
    int index, int gridx, int gridy, int gridwidth, int gridheight,
    double weightx, double weighty, int fill, Insets is) {

    if (container instanceof JFrame) {
        container = ((JFrame)container).getContentPane();
    } else if (container instanceof JDialog) {
        container = ((JDialog)container).getContentPane();
    }

    // add the component at the specified gridbag index
    container.add(component, index);

    // set the constraints
    GridBagLayout gbl = (GridBagLayout)container.getLayout();
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.gridx = gridx;
    gbc.gridy = gridy;
    gbc.gridwidth = gridwidth;
    gbc.gridheight = gridheight;
    gbc.weightx = weightx;
    gbc.weighty = weighty;
    gbc.fill = fill;
    if (is != null) gbc.insets = is;
    gbl.setConstraints(component, gbc);
}
 
Example 6
Source File: PolicyTool.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Add a component to the PolicyTool window
 */
void addNewComponent(Container container, JComponent component,
    int index, int gridx, int gridy, int gridwidth, int gridheight,
    double weightx, double weighty, int fill, Insets is) {

    if (container instanceof JFrame) {
        container = ((JFrame)container).getContentPane();
    } else if (container instanceof JDialog) {
        container = ((JDialog)container).getContentPane();
    }

    // add the component at the specified gridbag index
    container.add(component, index);

    // set the constraints
    GridBagLayout gbl = (GridBagLayout)container.getLayout();
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.gridx = gridx;
    gbc.gridy = gridy;
    gbc.gridwidth = gridwidth;
    gbc.gridheight = gridheight;
    gbc.weightx = weightx;
    gbc.weighty = weighty;
    gbc.fill = fill;
    if (is != null) gbc.insets = is;
    gbl.setConstraints(component, gbc);
}
 
Example 7
Source File: GridBagUtils.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Adds a component to a panel with a grid bag layout.
 *
 * @param panel the panel to which to add the component
 * @param comp  the component to be added
 * @param gbc   the grid bag constraints to be used, can be <code>null</code> if <code>code</code> is not
 *              <code>null</code>
 */
public static void addToPanel(JPanel panel, Component comp, GridBagConstraints gbc) {
    LayoutManager layoutManager = panel.getLayout();
    if (!(layoutManager instanceof GridBagLayout)) {
        throw new IllegalArgumentException("'panel' does not have a GridBagLayout manager");
    }
    GridBagLayout gbl = (GridBagLayout) layoutManager;
    gbl.setConstraints(comp, gbc);
    panel.add(comp);
}
 
Example 8
Source File: ChatLounge.java    From megamek with GNU General Public License v2.0 4 votes vote down vote up
private void setupMap() {

        panMap = new JPanel();

        mapSettings = MapSettings.getInstance(clientgui.getClient().getMapSettings());

        butConditions = new JButton(Messages.getString("ChatLounge.butConditions")); //$NON-NLS-1$
        butConditions.addActionListener(this);

        butRandomMap = new JButton(Messages.getString("BoardSelectionDialog.GeneratedMapSettings")); //$NON-NLS-1$
        butRandomMap.addActionListener(this);

        chkIncludeGround = new JCheckBox(Messages.getString("ChatLounge.IncludeGround")); //$NON-NLS-1$
        chkIncludeGround.addActionListener(this);

        chkIncludeSpace = new JCheckBox(Messages.getString("ChatLounge.IncludeSpace")); //$NON-NLS-1$
        chkIncludeSpace.addActionListener(this);

        setupGroundMap();
        setupSpaceMap();
        refreshSpaceGround();

        GridBagLayout gridbag = new GridBagLayout();
        GridBagConstraints c = new GridBagConstraints();
        panMap.setLayout(gridbag);

        c.fill = GridBagConstraints.NONE;
        c.insets = new Insets(1, 1, 1, 1);
        c.weightx = 0.0;
        c.weighty = 0.0;
        c.gridx = 0;
        c.gridy = 0;
        c.gridwidth = 1;
        c.gridheight = 1;
        c.anchor = GridBagConstraints.EAST;
        gridbag.setConstraints(butConditions, c);
        panMap.add(butConditions);

        c.fill = GridBagConstraints.NONE;
        c.weightx = 0.0;
        c.weighty = 0.0;
        c.gridx = 1;
        c.gridy = 0;
        c.gridwidth = 1;
        c.gridheight = 1;
        c.anchor = GridBagConstraints.WEST;
        gridbag.setConstraints(butRandomMap, c);
        panMap.add(butRandomMap);

        c.fill = GridBagConstraints.BOTH;
        c.insets = new Insets(4, 4, 4, 4);
        c.weightx = 1.0;
        c.weighty = 0.75;
        c.gridx = 0;
        c.gridy = 1;
        c.gridwidth = 2;
        c.gridheight = 1;
        c.anchor = GridBagConstraints.NORTHWEST;
        gridbag.setConstraints(panGroundMap, c);
        panMap.add(panGroundMap);

        c.fill = GridBagConstraints.BOTH;
        c.weightx = 1.0;
        c.weighty = 0.25;
        c.gridx = 0;
        c.gridy = 2;
        c.gridwidth = 2;
        c.gridheight = 1;
        gridbag.setConstraints(panSpaceMap, c);
        panMap.add(panSpaceMap);

    }
 
Example 9
Source File: CroppingPanel.java    From 3Dscript with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public CroppingPanel(ImagePlus image) {
	super();
	GridBagLayout gridbag = new GridBagLayout();
	GridBagConstraints c = new GridBagConstraints();
	setLayout(gridbag);

	int near = (int)Math.floor(getNear(image));
	int far = (int)Math.ceil(getFar(image));

	c.gridy = 0;
	nearfar = addDoubleSlider(
			"near/far",
			new int[] {near, far},
			new int[] {near, far},
			new Color(255, 0, 0, 100),
			c);

	bbX = addDoubleSlider(
			"x_range",
			new int[] {0, image.getWidth()},
			new int[] {0, image.getWidth()},
			new Color(255, 0, 0, 100),
			c);
	bbY = addDoubleSlider(
			"y_range",
			new int[] {0, image.getHeight()},
			new int[] {0, image.getHeight()},
			new Color(255, 0, 0, 100),
			c);
	bbZ = addDoubleSlider(
			"z_range",
			new int[] {0, image.getNSlices()},
			new int[] {0, image.getNSlices()},
			new Color(255, 0, 0, 100),
			c);

	nearfar.addSliderChangeListener(new DoubleSlider.Listener() {
		@Override
		public void sliderChanged() {
			fireNearFarChanged(nearfar.getMin(), nearfar.getMax());
		}
	});

	JPanel buttons = new JPanel(new FlowLayout(FlowLayout.RIGHT, 5, 0));
	allChannels = new JCheckBox("Apply to all channels", true);
	buttons.add(allChannels);

	JButton b = new JButton("Cut off ROI");
	buttons.add(b);

	c.gridx = 0;
	c.insets = new Insets(7, 0, 0, 0);
	c.fill = GridBagConstraints.NONE;
	c.anchor = GridBagConstraints.EAST;
	c.gridwidth = GridBagConstraints.REMAINDER;
	gridbag.setConstraints(buttons, c);
	add(buttons);
	b.addActionListener(new ActionListener() {
		@Override
		public void actionPerformed(ActionEvent e) {
			new Thread() {
				@Override
				public void run() {
					fireCutOffROI();
				}
			}.start();
		}
	});

	DoubleSlider.Listener bbListener = new DoubleSlider.Listener() {
		@Override
		public void sliderChanged() {
			fireBoundingBoxChanged(
					bbX.getMin(),
					bbY.getMin(),
					bbZ.getMin(),
					bbX.getMax(),
					bbY.getMax(),
					bbZ.getMax());
		}
	};
	bbX.addSliderChangeListener(bbListener);
	bbY.addSliderChangeListener(bbListener);
	bbZ.addSliderChangeListener(bbListener);
}
 
Example 10
Source File: DistributionModelPlotRenderer.java    From rapidminer-studio with GNU Affero General Public License v3.0 4 votes vote down vote up
public DistributionModelPlotVisualizer(DistributionModel distributionModel) {
	super(distributionModel, "plot_view");
	setLayout(new BorderLayout());
	DataTable table = new SimpleDataTable("Dummy", distributionModel.getAttributeNames());
	final PlotterConfigurationModel settings = new PlotterConfigurationModel(
			PlotterConfigurationModel.COMPLETE_PLOTTER_SELECTION, table);
	final Plotter plotter = new DistributionPlotter(settings, distributionModel);
	settings.setPlotter(plotter);

	plotterComponent = plotter.getPlotter();
	plotterComponent.setBorder(BorderFactory.createMatteBorder(15, 0, 10, 5, Colors.WHITE));
	add(plotterComponent, BorderLayout.CENTER);

	final ListeningJComboBox<String> combo = new ListeningJComboBox<>(settings,
			PlotterAdapter.PARAMETER_PLOT_COLUMN + "_"
					+ PlotterAdapter.transformParameterName(plotter.getPlotName()),
			distributionModel.getAttributeNames());
	combo.setPreferredSize(new Dimension(200, PropertyPanel.VALUE_CELL_EDITOR_HEIGHT));
	combo.putClientProperty(RapidLookTools.PROPERTY_INPUT_BACKGROUND_DARK, true);
	GridBagLayout layout = new GridBagLayout();
	GridBagConstraints c = new GridBagConstraints();
	c.fill = GridBagConstraints.BOTH;
	c.weighty = 0.0d;
	c.weightx = 1.0d;
	c.insets = new Insets(4, 4, 4, 4);
	c.gridwidth = GridBagConstraints.REMAINDER;

	JPanel boxPanel = new JPanel(layout);
	boxPanel.setBorder(BorderFactory.createMatteBorder(10, 8, 5, 10, Colors.WHITE));
	boxPanel.setOpaque(true);
	boxPanel.setBackground(Colors.WHITE);
	JLabel label = new JLabel("Attribute:");
	layout.setConstraints(label, c);
	boxPanel.add(label);

	layout.setConstraints(combo, c);
	boxPanel.add(combo);

	final JCheckBox rotateLabels = new JCheckBox("Rotate Labels", false);
	layout.setConstraints(rotateLabels, c);
	boxPanel.add(rotateLabels);

	c.weighty = 1.0;
	JLabel filler = new JLabel();
	layout.setConstraints(filler, c);
	boxPanel.add(filler);

	add(boxPanel, BorderLayout.WEST);

	combo.addActionListener(new ActionListener() {

		@Override
		public void actionPerformed(ActionEvent arg0) {
			settings.setParameterAsString(PlotterAdapter.PARAMETER_PLOT_COLUMN, combo.getSelectedItem().toString());
		}
	});

	rotateLabels.addActionListener(new ActionListener() {

		@Override
		public void actionPerformed(ActionEvent e) {
			settings.setParameterAsBoolean(LabelRotatingPlotterAdapter.PARAMETER_ROTATE_LABELS,
					rotateLabels.isSelected());
		}
	});

	combo.setSelectedIndex(0);
}
 
Example 11
Source File: NeutralLossSetHighlightDialog.java    From mzmine2 with GNU General Public License v2.0 4 votes vote down vote up
public NeutralLossSetHighlightDialog(NeutralLossPlot plot, String command) {

    // Make dialog modal
    super(MZmineCore.getDesktop().getMainWindow(), "", true);

    this.desktop = MZmineCore.getDesktop();
    this.plot = plot;
    this.rangeType = command;

    String title = "Highlight ";
    if (command.equals("HIGHLIGHT_PRECURSOR"))
      title += "precursor m/z range";
    else if (command.equals("HIGHLIGHT_NEUTRALLOSS"))
      title += "neutral loss m/z range";
    setTitle(title);

    GridBagConstraints constraints = new GridBagConstraints();

    // set default layout constraints
    constraints.fill = GridBagConstraints.HORIZONTAL;
    constraints.anchor = GridBagConstraints.WEST;
    constraints.insets = new Insets(PADDING_SIZE, PADDING_SIZE, PADDING_SIZE, PADDING_SIZE);

    JComponent comp;
    GridBagLayout layout = new GridBagLayout();

    JPanel components = new JPanel(layout);

    NumberFormat format = NumberFormat.getNumberInstance();

    comp = GUIUtils.addLabel(components, "Minimum m/z");
    constraints.gridx = 0;
    constraints.gridy = 0;
    constraints.gridwidth = 1;
    constraints.gridheight = 1;
    layout.setConstraints(comp, constraints);

    constraints.weightx = 1;
    fieldMinMZ = new JFormattedTextField(format);
    fieldMinMZ.setPreferredSize(new Dimension(50, fieldMinMZ.getPreferredSize().height));
    constraints.gridx = 1;
    components.add(fieldMinMZ, constraints);
    constraints.weightx = 0;

    comp = GUIUtils.addLabel(components, "Maximum m/z");
    constraints.gridx = 0;
    constraints.gridy = 1;
    layout.setConstraints(comp, constraints);

    constraints.weightx = 1;
    fieldMaxMZ = new JFormattedTextField(format);
    constraints.gridx = 1;
    components.add(fieldMaxMZ, constraints);
    constraints.weightx = 0;

    comp = GUIUtils.addSeparator(components, PADDING_SIZE);
    constraints.gridx = 0;
    constraints.gridy = 2;
    constraints.gridwidth = 3;
    constraints.gridheight = 1;
    layout.setConstraints(comp, constraints);

    JPanel buttonsPanel = new JPanel();
    btnOK = GUIUtils.addButton(buttonsPanel, "OK", null, this);
    btnCancel = GUIUtils.addButton(buttonsPanel, "Cancel", null, this);
    constraints.gridx = 0;
    constraints.gridy = 3;
    constraints.gridwidth = 3;
    constraints.gridheight = 1;
    components.add(buttonsPanel, constraints);

    GUIUtils.addMargin(components, PADDING_SIZE);
    add(components);

    // finalize the dialog
    pack();
    setLocationRelativeTo(MZmineCore.getDesktop().getMainWindow());
    setResizable(false);

  }
 
Example 12
Source File: LetterNotesEditor.java    From jmg with GNU General Public License v2.0 4 votes vote down vote up
private void placeControls() {
    GridBagLayout      layout = new GridBagLayout();        
    GridBagConstraints c      = new GridBagConstraints();       
    setLayout(layout);

    c.fill  = GridBagConstraints.BOTH;
    c.weightx = 0.5;        
    c.gridwidth  = 5;
    c.gridheight = 1;
    
    c.gridx      = 0;
    c.gridy      = 0;
    layout.setConstraints(inputLabel, c); 
    add( inputLabel);
 
    c.gridx      = 0;
    c.gridy      = 1;
    c.gridheight = 10;
    layout.setConstraints(notesInput, c); 
    add( notesInput );

    c.gridx      = 2;
    c.gridy      = 12;
    c.gridheight = 1;
    c.gridwidth  = 1;
    layout.setConstraints(okButton, c); 
    add( okButton );
    okButton.addActionListener( this );
    
    c.gridx      = 3;
    c.gridy      = 12;
    c.gridwidth  = 1;
    layout.setConstraints(playButton, c); 
    add( playButton );
    playButton.addActionListener(this);

    c.gridx      = 4;
    c.gridy      = 12;
    c.gridwidth  = 1;
    layout.setConstraints(cancelButton, c); 
    add( cancelButton );
    cancelButton.addActionListener(this);

    c.gridx      = 1;
    c.gridy      = 15;
    c.gridwidth  = 5;
    c.gridheight = 5;
    layout.setConstraints(inputList, c); 
    add(inputList);

    c.gridx      = 1;
    c.gridy      = 20;
    c.gridwidth  = 5;
    c.gridheight = 1;
    layout.setConstraints(copyButton, c); 
    add(copyButton);
    copyButton.addActionListener( this );
            
}
 
Example 13
Source File: DataInstaller.java    From pcgen with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Build the user interface ready for display.
 */
private void initComponents()
{
	GridBagConstraints gbc = new GridBagConstraints();
	gbc.fill = GridBagConstraints.HORIZONTAL;
	gbc.anchor = GridBagConstraints.WEST;
	gbc.insets = new Insets(2, 2, 2, 2);
	GridBagLayout gridbag = new GridBagLayout();
	setTitle(TITLE);
	setLayout(gridbag);

	// Data set selection row
	Utility.buildConstraints(gbc, 0, 0, 1, 1, 0.0, 0.0);
	JLabel dataSetLabel = new JLabel(LanguageBundle.getString("in_diDataSet"), SwingConstants.RIGHT);
	gridbag.setConstraints(dataSetLabel, gbc);
	add(dataSetLabel, gbc);

	Utility.buildConstraints(gbc, 1, 0, 2, 1, 1.0, 0.0);
	dataSetSel = new JTextField("", SwingConstants.WEST);
	dataSetSel.setEditable(false);
	gridbag.setConstraints(dataSetSel, gbc);
	add(dataSetSel, gbc);

	Utility.buildConstraints(gbc, 3, 0, 1, 1, 0.0, 0.0);
	gbc.fill = GridBagConstraints.NONE;
	selectButton = new JButton();
	CommonMenuText.name(selectButton, "select"); //$NON-NLS-1$
	gridbag.setConstraints(selectButton, gbc);
	add(selectButton, gbc);
	selectButton.addActionListener(listener);

	// Data set details row
	Utility.buildConstraints(gbc, 0, 1, 4, 1, 1.0, 1.0);
	dataSetDetails = new JFXPanelFromResource<>(
			SimpleHtmlPanelController.class,
			"SimpleHtmlPanel.fxml"
	);
	dataSetDetails.setPreferredSize(new Dimension(400, 200));
	dataSetDetails.setBackground(getBackground());
	gbc.fill = GridBagConstraints.BOTH;
	JScrollPane jScrollPane = new JScrollPane();
	jScrollPane.setViewportView(dataSetDetails);
	gridbag.setConstraints(jScrollPane, gbc);
	add(jScrollPane, gbc);

	// Location row
	Utility.buildConstraints(gbc, 0, 2, 1, 1, 0.0, 0.0);
	gbc.fill = GridBagConstraints.HORIZONTAL;
	JLabel locLabel = new JLabel(LanguageBundle.getString("in_diLocation"), SwingConstants.RIGHT);
	gridbag.setConstraints(locLabel, gbc);
	add(locLabel, gbc);

	ButtonGroup exclusiveGroup = new ButtonGroup();
	locDataButton = new JRadioButton(LanguageBundle.getString("in_diData"));
	locDataButton.setToolTipText(LanguageBundle.getString("in_diData_tip"));
	exclusiveGroup.add(locDataButton);
	locVendorDataButton = new JRadioButton(LanguageBundle.getString("in_diVendorData"));
	locVendorDataButton.setToolTipText(LanguageBundle.getString("in_diVendorData_tip"));
	exclusiveGroup.add(locVendorDataButton);
	locHomebrewDataButton = new JRadioButton(LanguageBundle.getString("in_diHomebrewData"));
	locHomebrewDataButton.setToolTipText(LanguageBundle.getString("in_diHomebrewData_tip"));
	exclusiveGroup.add(locHomebrewDataButton);
	JPanel optionsPanel = new JPanel();
	optionsPanel.add(locDataButton);
	optionsPanel.add(locVendorDataButton);
	optionsPanel.add(locHomebrewDataButton);
	Utility.buildConstraints(gbc, 1, 2, 3, 1, 0.0, 0.0);
	gridbag.setConstraints(optionsPanel, gbc);
	gbc.fill = GridBagConstraints.NONE;
	gbc.anchor = GridBagConstraints.WEST;
	add(optionsPanel, gbc);

	// Buttons row
	installButton = new JButton();
	CommonMenuText.name(installButton, "diInstall"); //$NON-NLS-1$
	installButton.addActionListener(listener);
	closeButton = new JButton();
	CommonMenuText.name(closeButton, "close"); //$NON-NLS-1$
	closeButton.addActionListener(listener);

	JPanel buttonsPanel = new JPanel();
	buttonsPanel.add(installButton);
	buttonsPanel.add(closeButton);
	Utility.buildConstraints(gbc, 2, 3, 2, 1, 0.0, 0.0);
	gridbag.setConstraints(buttonsPanel, gbc);
	gbc.fill = GridBagConstraints.NONE;
	gbc.anchor = GridBagConstraints.EAST;
	add(buttonsPanel, gbc);

	pack();
}
 
Example 14
Source File: Font2DTest.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
private void setupPanel() {
    GridBagLayout gbl = new GridBagLayout();
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.weightx = 1;
    gbc.insets = new Insets( 2, 0, 2, 2 );
    this.setLayout( gbl );

    addLabeledComponentToGBL( "Font: ", fontMenu, gbl, gbc, this );
    addLabeledComponentToGBL( "Size: ", sizeField, gbl, gbc, this );
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    addLabeledComponentToGBL( "Font Transform:",
                              transformMenu, gbl, gbc, this );
    gbc.gridwidth = 1;

    addLabeledComponentToGBL( "Range: ", rm, gbl, gbc, this );
    addLabeledComponentToGBL( "Style: ", styleMenu, gbl, gbc, this );
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    addLabeledComponentToGBL( "Graphics Transform: ",
                              transformMenuG2, gbl, gbc, this );
    gbc.gridwidth = 1;

    gbc.anchor = GridBagConstraints.WEST;
    addLabeledComponentToGBL( "Method: ", methodsMenu, gbl, gbc, this );
    addLabeledComponentToGBL("", null, gbl, gbc, this);
    gbc.anchor = GridBagConstraints.EAST;
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    addLabeledComponentToGBL( "Text to use:", textMenu, gbl, gbc, this );

    gbc.weightx=1;
    gbc.gridwidth = 1;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.anchor = GridBagConstraints.WEST;
    addLabeledComponentToGBL("LCD contrast: ",
                              contrastSlider, gbl, gbc, this);

    gbc.gridwidth = 1;
    gbc.fill = GridBagConstraints.NONE;
    addLabeledComponentToGBL("Antialiasing: ",
                              antiAliasMenu, gbl, gbc, this);

    gbc.anchor = GridBagConstraints.EAST;
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    addLabeledComponentToGBL("Fractional metrics: ",
                              fracMetricsMenu, gbl, gbc, this);

    gbc.weightx = 1;
    gbc.weighty = 1;
    gbc.anchor = GridBagConstraints.WEST;
    gbc.insets = new Insets( 2, 0, 0, 2 );
    gbc.fill = GridBagConstraints.BOTH;
    gbl.setConstraints( fp, gbc );
    this.add( fp );

    gbc.weighty = 0;
    gbc.insets = new Insets( 0, 2, 0, 0 );
    gbl.setConstraints( statusBar, gbc );
    this.add( statusBar );
}
 
Example 15
Source File: GUIHelper.java    From SPIM_Registration with GNU General Public License v2.0 4 votes vote down vote up
/**
	 * A copy of Curtis's method
	 * 
	 * https://github.com/openmicroscopy/bioformats/blob/v4.4.8/components/loci-plugins/src/loci/plugins/util/WindowTools.java#L72
	 * 
	 *
	 * @param pane
	 */
	public static void addScrollBars(Container pane) {
//        * <dependency>
//        * <groupId>${bio-formats.groupId}</groupId>
//        * <artifactId>loci_plugins</artifactId>
//        * <version>${bio-formats.version}</version>
//        * </dependency>

		GridBagLayout layout = (GridBagLayout) pane.getLayout();

		// extract components
		int count = pane.getComponentCount();
		Component[] c = new Component[count];
		GridBagConstraints[] gbc = new GridBagConstraints[count];
		for (int i = 0; i < count; i++) {
			c[i] = pane.getComponent(i);
			gbc[i] = layout.getConstraints(c[i]);
		}

		// clear components
		pane.removeAll();
		layout.invalidateLayout(pane);

		// create new container panel
		Panel newPane = new Panel();
		GridBagLayout newLayout = new GridBagLayout();
		newPane.setLayout(newLayout);
		for (int i = 0; i < count; i++) {
			newLayout.setConstraints(c[i], gbc[i]);
			newPane.add(c[i]);
		}

		// HACK - get preferred size for container panel
		// NB: don't know a better way:
		// - newPane.getPreferredSize() doesn't work
		// - newLayout.preferredLayoutSize(newPane) doesn't work
		Frame f = new Frame();
		f.setLayout(new BorderLayout());
		f.add(newPane, BorderLayout.CENTER);
		f.pack();
		final Dimension size = newPane.getSize();
		f.remove(newPane);
		f.dispose();

		// compute best size for scrollable viewport
		size.width += 25;
		size.height += 15;
		Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
		int maxWidth = 7 * screen.width / 8;
		int maxHeight = 3 * screen.height / 4;
		if (size.width > maxWidth)
			size.width = maxWidth;
		if (size.height > maxHeight)
			size.height = maxHeight;

		// create scroll pane
		ScrollPane scroll = new ScrollPane() {
			private static final long serialVersionUID = 1L;

			public Dimension getPreferredSize() {
				return size;
			}
		};
		scroll.add(newPane);

		// add scroll pane to original container
		GridBagConstraints constraints = new GridBagConstraints();
		constraints.gridwidth = GridBagConstraints.REMAINDER;
		constraints.fill = GridBagConstraints.BOTH;
		constraints.weightx = 1.0;
		constraints.weighty = 1.0;
		layout.setConstraints(scroll, constraints);
		pane.add(scroll);
	}
 
Example 16
Source File: ParmScreen.java    From jmg with GNU General Public License v2.0 4 votes vote down vote up
private void placeControls() {
	GridBagLayout      layout = new GridBagLayout();    	
	GridBagConstraints c      = new GridBagConstraints();    	
	setLayout(layout);

	c.fill  = GridBagConstraints.BOTH;
	c.weightx = 0.5;		
	c.gridwidth  = 1;
	c.gridheight = 1;
	
	c.gridx      = 0;
	c.gridy      = 0;
	c.gridheight = 3;
	layout.setConstraints(instrumentLabel, c); 
	add( instrumentLabel);
	c.gridx     = 1;
	layout.setConstraints(instrumentList, c); 
	add( instrumentList);
	c.gridwidth = GridBagConstraints.REMAINDER; 		
	c.gridx     = 2;
               Panel ibPanel = new Panel();
               ibPanel.add(instrumentButton);
	layout.setConstraints(ibPanel, c); 
	add(ibPanel);      	
	c.gridheight = 1;
	
	c.gridwidth  = 1;
	c.gridx     = 0;
	c.gridy     = 3;
	layout.setConstraints(volumeLabel, c); 
	add( volumeLabel);
	c.gridx     = 1;
	layout.setConstraints(volumeList, c); 
	add( volumeList);
	c.gridwidth = GridBagConstraints.REMAINDER; 		
	c.gridx     = 2;
               Panel vbPanel = new Panel();
               vbPanel.add(volumeButton);
	layout.setConstraints(vbPanel, c); 
	add(vbPanel);      	
	
	c.gridwidth  = 1;
	c.gridx     = 0;
	c.gridy     = 4;
	layout.setConstraints(tempoLabel, c); 
	add( tempoLabel);
	c.gridx     = 1;
	layout.setConstraints(tempoList, c); 
	add( tempoList);
	c.gridwidth = GridBagConstraints.REMAINDER; 		
	c.gridx     = 2;
               Panel tbPanel = new Panel();
               tbPanel.add(tempoButton);
	layout.setConstraints(tbPanel, c); 
	add(tbPanel);      	
	
	c.gridwidth  = 1;
	c.gridx = 1;
	c.gridy = 5;
	layout.setConstraints(closeButton, c); 
	add(closeButton);

	instrumentButton.addActionListener(this);
	volumeButton.addActionListener(this);     
	tempoButton.addActionListener(this);      
	closeButton.addActionListener(this);      

}
 
Example 17
Source File: DataInstaller.java    From pcgen with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Build the user interface ready for display.
 */
private void initComponents()
{
	GridBagConstraints gbc = new GridBagConstraints();
	gbc.fill = GridBagConstraints.HORIZONTAL;
	gbc.anchor = GridBagConstraints.WEST;
	gbc.insets = new Insets(2, 2, 2, 2);
	GridBagLayout gridbag = new GridBagLayout();
	setTitle(TITLE);
	setLayout(gridbag);

	// Data set selection row
	Utility.buildConstraints(gbc, 0, 0, 1, 1, 0.0, 0.0);
	JLabel dataSetLabel = new JLabel(LanguageBundle.getString("in_diDataSet"), SwingConstants.RIGHT);
	gridbag.setConstraints(dataSetLabel, gbc);
	add(dataSetLabel, gbc);

	Utility.buildConstraints(gbc, 1, 0, 2, 1, 1.0, 0.0);
	dataSetSel = new JTextField("", SwingConstants.WEST);
	dataSetSel.setEditable(false);
	gridbag.setConstraints(dataSetSel, gbc);
	add(dataSetSel, gbc);

	Utility.buildConstraints(gbc, 3, 0, 1, 1, 0.0, 0.0);
	gbc.fill = GridBagConstraints.NONE;
	selectButton = new JButton();
	CommonMenuText.name(selectButton, "select"); //$NON-NLS-1$
	gridbag.setConstraints(selectButton, gbc);
	add(selectButton, gbc);
	selectButton.addActionListener(listener);

	// Data set details row
	Utility.buildConstraints(gbc, 0, 1, 4, 1, 1.0, 1.0);
	dataSetDetails = new JFXPanelFromResource<>(
			SimpleHtmlPanelController.class,
			"SimpleHtmlPanel.fxml"
	);
	dataSetDetails.setPreferredSize(new Dimension(400, 200));
	dataSetDetails.setBackground(getBackground());
	gbc.fill = GridBagConstraints.BOTH;
	JScrollPane jScrollPane = new JScrollPane();
	jScrollPane.setViewportView(dataSetDetails);
	gridbag.setConstraints(jScrollPane, gbc);
	add(jScrollPane, gbc);

	// Location row
	Utility.buildConstraints(gbc, 0, 2, 1, 1, 0.0, 0.0);
	gbc.fill = GridBagConstraints.HORIZONTAL;
	JLabel locLabel = new JLabel(LanguageBundle.getString("in_diLocation"), SwingConstants.RIGHT);
	gridbag.setConstraints(locLabel, gbc);
	add(locLabel, gbc);

	ButtonGroup exclusiveGroup = new ButtonGroup();
	locDataButton = new JRadioButton(LanguageBundle.getString("in_diData"));
	locDataButton.setToolTipText(LanguageBundle.getString("in_diData_tip"));
	exclusiveGroup.add(locDataButton);
	locVendorDataButton = new JRadioButton(LanguageBundle.getString("in_diVendorData"));
	locVendorDataButton.setToolTipText(LanguageBundle.getString("in_diVendorData_tip"));
	exclusiveGroup.add(locVendorDataButton);
	locHomebrewDataButton = new JRadioButton(LanguageBundle.getString("in_diHomebrewData"));
	locHomebrewDataButton.setToolTipText(LanguageBundle.getString("in_diHomebrewData_tip"));
	exclusiveGroup.add(locHomebrewDataButton);
	JPanel optionsPanel = new JPanel();
	optionsPanel.add(locDataButton);
	optionsPanel.add(locVendorDataButton);
	optionsPanel.add(locHomebrewDataButton);
	Utility.buildConstraints(gbc, 1, 2, 3, 1, 0.0, 0.0);
	gridbag.setConstraints(optionsPanel, gbc);
	gbc.fill = GridBagConstraints.NONE;
	gbc.anchor = GridBagConstraints.WEST;
	add(optionsPanel, gbc);

	// Buttons row
	installButton = new JButton();
	CommonMenuText.name(installButton, "diInstall"); //$NON-NLS-1$
	installButton.addActionListener(listener);
	closeButton = new JButton();
	CommonMenuText.name(closeButton, "close"); //$NON-NLS-1$
	closeButton.addActionListener(listener);

	JPanel buttonsPanel = new JPanel();
	buttonsPanel.add(installButton);
	buttonsPanel.add(closeButton);
	Utility.buildConstraints(gbc, 2, 3, 2, 1, 0.0, 0.0);
	gridbag.setConstraints(buttonsPanel, gbc);
	gbc.fill = GridBagConstraints.NONE;
	gbc.anchor = GridBagConstraints.EAST;
	add(buttonsPanel, gbc);

	pack();
}
 
Example 18
Source File: Font2DTest.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
private void setupPanel() {
    GridBagLayout gbl = new GridBagLayout();
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.weightx = 1;
    gbc.insets = new Insets( 2, 0, 2, 2 );
    this.setLayout( gbl );

    addLabeledComponentToGBL( "Font: ", fontMenu, gbl, gbc, this );
    addLabeledComponentToGBL( "Size: ", sizeField, gbl, gbc, this );
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    addLabeledComponentToGBL( "Font Transform:",
                              transformMenu, gbl, gbc, this );
    gbc.gridwidth = 1;

    addLabeledComponentToGBL( "Range: ", rm, gbl, gbc, this );
    addLabeledComponentToGBL( "Style: ", styleMenu, gbl, gbc, this );
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    addLabeledComponentToGBL( "Graphics Transform: ",
                              transformMenuG2, gbl, gbc, this );
    gbc.gridwidth = 1;

    gbc.anchor = GridBagConstraints.WEST;
    addLabeledComponentToGBL( "Method: ", methodsMenu, gbl, gbc, this );
    addLabeledComponentToGBL("", null, gbl, gbc, this);
    gbc.anchor = GridBagConstraints.EAST;
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    addLabeledComponentToGBL( "Text to use:", textMenu, gbl, gbc, this );

    gbc.weightx=1;
    gbc.gridwidth = 1;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.anchor = GridBagConstraints.WEST;
    addLabeledComponentToGBL("LCD contrast: ",
                              contrastSlider, gbl, gbc, this);

    gbc.gridwidth = 1;
    gbc.fill = GridBagConstraints.NONE;
    addLabeledComponentToGBL("Antialiasing: ",
                              antiAliasMenu, gbl, gbc, this);

    gbc.anchor = GridBagConstraints.EAST;
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    addLabeledComponentToGBL("Fractional metrics: ",
                              fracMetricsMenu, gbl, gbc, this);

    gbc.weightx = 1;
    gbc.weighty = 1;
    gbc.anchor = GridBagConstraints.WEST;
    gbc.insets = new Insets( 2, 0, 0, 2 );
    gbc.fill = GridBagConstraints.BOTH;
    gbl.setConstraints( fp, gbc );
    this.add( fp );

    gbc.weighty = 0;
    gbc.insets = new Insets( 0, 2, 0, 0 );
    gbl.setConstraints( statusBar, gbc );
    this.add( statusBar );
}
 
Example 19
Source File: BuildCircuitButton.java    From Logisim with GNU General Public License v3.0 4 votes vote down vote up
DialogPanel() {
	List<Project> projects = Projects.getOpenProjects();
	Object[] options = new Object[projects.size()];
	Object initialSelection = null;
	for (int i = 0; i < options.length; i++) {
		Project proj = projects.get(i);
		options[i] = new ProjectItem(proj);
		if (proj == model.getCurrentProject()) {
			initialSelection = options[i];
		}
	}
	project = new JComboBox<Object>(options);
	if (options.length == 1) {
		project.setSelectedItem(options[0]);
		project.setEnabled(false);
	} else if (initialSelection != null) {
		project.setSelectedItem(initialSelection);
	}

	Circuit defaultCircuit = model.getCurrentCircuit();
	if (defaultCircuit != null) {
		name.setText(defaultCircuit.getName());
		name.selectAll();
	}

	VariableList outputs = model.getOutputs();
	boolean enableNands = true;
	for (int i = 0; i < outputs.size(); i++) {
		String output = outputs.get(i);
		Expression expr = model.getOutputExpressions().getExpression(output);
		if (expr != null && expr.containsXor()) {
			enableNands = false;
			break;
		}
	}
	nands.setEnabled(enableNands);

	GridBagLayout gb = new GridBagLayout();
	GridBagConstraints gc = new GridBagConstraints();
	setLayout(gb);
	gc.anchor = GridBagConstraints.LINE_START;
	gc.fill = GridBagConstraints.NONE;

	gc.gridx = 0;
	gc.gridy = 0;
	gb.setConstraints(projectLabel, gc);
	add(projectLabel);
	gc.gridx = 1;
	gb.setConstraints(project, gc);
	add(project);
	gc.gridy++;
	gc.gridx = 0;
	gb.setConstraints(nameLabel, gc);
	add(nameLabel);
	gc.gridx = 1;
	gb.setConstraints(name, gc);
	add(name);
	gc.gridy++;
	gb.setConstraints(twoInputs, gc);
	add(twoInputs);
	gc.gridy++;
	gb.setConstraints(nands, gc);
	add(nands);

	projectLabel.setText(Strings.get("buildProjectLabel"));
	nameLabel.setText(Strings.get("buildNameLabel"));
	twoInputs.setText(Strings.get("buildTwoInputsLabel"));
	nands.setText(Strings.get("buildNandsLabel"));
}
 
Example 20
Source File: OperatorTreeCellRenderer.java    From rapidminer-studio with GNU Affero General Public License v3.0 4 votes vote down vote up
public OperatorPanel() {
	setBackground(new java.awt.Color(0, 0, 0, 0));
	setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));

	GridBagLayout layout = new GridBagLayout();
	setLayout(layout);
	GridBagConstraints c = new GridBagConstraints();
	c.anchor = GridBagConstraints.LINE_START;
	c.fill = GridBagConstraints.NONE;
	c.weightx = 0;

	layout.setConstraints(iconLabel, c);
	add(iconLabel);

	// name panel
	JPanel namePanel = new JPanel();
	namePanel.setBackground(new java.awt.Color(0, 0, 0, 0));
	GridBagLayout nameLayout = new GridBagLayout();
	GridBagConstraints nameC = new GridBagConstraints();
	nameC.fill = GridBagConstraints.BOTH;
	nameC.insets = new Insets(0, 5, 0, 5);
	namePanel.setLayout(nameLayout);

	nameLabel.setHorizontalAlignment(SwingConstants.LEFT);
	nameLabel.setFont(getFont().deriveFont(Font.PLAIN, 12));
	nameC.gridwidth = GridBagConstraints.REMAINDER;
	nameLayout.setConstraints(nameLabel, nameC);
	namePanel.add(nameLabel);

	classLabel.setHorizontalAlignment(SwingConstants.LEFT);
	classLabel.setFont(getFont().deriveFont(Font.PLAIN, 10));
	nameLayout.setConstraints(classLabel, nameC);
	namePanel.add(classLabel);

	c.weightx = 1;
	add(namePanel, c);

	c.gridwidth = GridBagConstraints.RELATIVE;
	c.weightx = 0;

	layout.setConstraints(breakpoint, c);
	add(breakpoint);

	c.gridwidth = GridBagConstraints.REMAINDER;

	layout.setConstraints(error, c);
	add(error);
}