Example usage for javax.swing Box createRigidArea

List of usage examples for javax.swing Box createRigidArea

Introduction

In this page you can find the example usage for javax.swing Box createRigidArea.

Prototype

public static Component createRigidArea(Dimension d) 

Source Link

Document

Creates an invisible component that's always the specified size.

Usage

From source file:Main.java

public Main() {
    super("Demostrating BoxLayout");
    final int SIZE = 3;
    Container c = getContentPane();
    c.setLayout(new BorderLayout(30, 30));

    Box boxes[] = new Box[4];

    boxes[0] = Box.createHorizontalBox();
    boxes[1] = Box.createVerticalBox();
    boxes[2] = Box.createHorizontalBox();
    boxes[3] = Box.createVerticalBox();

    for (int i = 0; i < SIZE; i++)
        boxes[0].add(new JButton("boxes[0]: " + i));

    for (int i = 0; i < SIZE; i++) {
        boxes[1].add(Box.createVerticalStrut(25));
        boxes[1].add(new JButton("boxes[1]: " + i));
    }//from  w  w  w.j  a va  2 s.  c o  m

    for (int i = 0; i < SIZE; i++) {
        boxes[2].add(Box.createHorizontalGlue());
        boxes[2].add(new JButton("boxes[2]: " + i));
    }

    for (int i = 0; i < SIZE; i++) {
        boxes[3].add(Box.createRigidArea(new Dimension(12, 8)));
        boxes[3].add(new JButton("boxes[3]: " + i));
    }

    JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));

    for (int i = 0; i < SIZE; i++) {
        panel.add(Box.createGlue());
        panel.add(new JButton("panel: " + i));
    }

    c.add(boxes[0], BorderLayout.NORTH);
    c.add(boxes[1], BorderLayout.EAST);
    c.add(boxes[2], BorderLayout.SOUTH);
    c.add(boxes[3], BorderLayout.WEST);
    c.add(panel, BorderLayout.CENTER);

    setSize(350, 300);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setVisible(true);

}

From source file:TextureByReference.java

public JPanel buildGui() {
    flipB = new JCheckBox("flip image", true);
    flipB.addItemListener(this);
    javax.swing.Box flipBox = new javax.swing.Box(BoxLayout.Y_AXIS);
    flipBox.add(flipB);//www .  j  a  v a2s .com
    Component strut1 = flipBox.createVerticalStrut(flipB.getPreferredSize().height);
    Component strut2 = flipBox.createVerticalStrut(flipB.getPreferredSize().height);
    Component strut3 = flipBox.createVerticalStrut(flipB.getPreferredSize().height);
    Component strut4 = flipBox.createVerticalStrut(flipB.getPreferredSize().height);
    Component strut5 = flipBox.createVerticalStrut(flipB.getPreferredSize().height);
    flipBox.add(strut1);
    flipBox.add(strut2);
    flipBox.add(strut3);
    flipBox.add(strut4);
    flipBox.add(strut5);

    yUp = new JRadioButton("y up");
    yUp.addActionListener(this);
    yUp.setSelected(true);
    yDown = new JRadioButton("y down");
    yDown.addActionListener(this);
    ButtonGroup yGroup = new ButtonGroup();
    yGroup.add(yUp);
    yGroup.add(yDown);
    JLabel yLabel = new JLabel("Image Orientation:");
    javax.swing.Box yBox = new javax.swing.Box(BoxLayout.Y_AXIS);
    yBox.add(yLabel);
    yBox.add(yUp);
    yBox.add(yDown);
    strut1 = yBox.createVerticalStrut(yUp.getPreferredSize().height);
    strut2 = yBox.createVerticalStrut(yUp.getPreferredSize().height);
    strut3 = yBox.createVerticalStrut(yUp.getPreferredSize().height);
    yBox.add(strut1);
    yBox.add(strut2);
    yBox.add(strut3);

    texByRef = new JRadioButton("by reference");
    texByRef.addActionListener(this);
    texByRef.setSelected(true);
    texByCopy = new JRadioButton("by copy");
    texByCopy.addActionListener(this);
    ButtonGroup texGroup = new ButtonGroup();
    texGroup.add(texByRef);
    texGroup.add(texByCopy);
    JLabel texLabel = new JLabel("Texture:*");
    javax.swing.Box texBox = new javax.swing.Box(BoxLayout.Y_AXIS);
    texBox.add(texLabel);
    texBox.add(texByRef);
    texBox.add(texByCopy);
    strut1 = texBox.createVerticalStrut(texByRef.getPreferredSize().height);
    strut2 = texBox.createVerticalStrut(texByRef.getPreferredSize().height);
    strut3 = texBox.createVerticalStrut(texByRef.getPreferredSize().height);
    texBox.add(strut1);
    texBox.add(strut2);
    texBox.add(strut3);

    geomByRef = new JRadioButton("by reference");
    geomByRef.addActionListener(this);
    geomByRef.setSelected(true);
    geomByCopy = new JRadioButton("by copy");
    geomByCopy.addActionListener(this);
    ButtonGroup geomGroup = new ButtonGroup();
    geomGroup.add(geomByRef);
    geomGroup.add(geomByCopy);
    JLabel geomLabel = new JLabel("Geometry:");
    javax.swing.Box geomBox = new javax.swing.Box(BoxLayout.Y_AXIS);
    geomBox.add(geomLabel);
    geomBox.add(geomByRef);
    geomBox.add(geomByCopy);
    strut1 = geomBox.createVerticalStrut(geomByRef.getPreferredSize().height);
    strut2 = geomBox.createVerticalStrut(geomByRef.getPreferredSize().height);
    strut3 = geomBox.createVerticalStrut(geomByRef.getPreferredSize().height);
    geomBox.add(strut1);
    geomBox.add(strut2);
    geomBox.add(strut3);

    img4ByteABGR = new JRadioButton("TYPE_4BYTE_ABGR");
    img4ByteABGR.addActionListener(this);
    img4ByteABGR.setSelected(true);
    img3ByteBGR = new JRadioButton("TYPE_3BYTE_BGR");
    img3ByteBGR.addActionListener(this);
    imgIntARGB = new JRadioButton("TYPE_INT_ARGB");
    imgIntARGB.addActionListener(this);
    imgCustomRGBA = new JRadioButton("TYPE_CUSTOM RGBA");
    imgCustomRGBA.addActionListener(this);
    imgCustomRGB = new JRadioButton("TYPE_CUSTOM RGB");
    imgCustomRGB.addActionListener(this);
    ButtonGroup imgGroup = new ButtonGroup();
    imgGroup.add(img4ByteABGR);
    imgGroup.add(img3ByteBGR);
    imgGroup.add(imgIntARGB);
    imgGroup.add(imgCustomRGBA);
    imgGroup.add(imgCustomRGB);
    JLabel imgLabel = new JLabel("Image Type:*");
    javax.swing.Box imgBox = new javax.swing.Box(BoxLayout.Y_AXIS);
    imgBox.add(imgLabel);
    imgBox.add(img4ByteABGR);
    imgBox.add(img3ByteBGR);
    imgBox.add(imgIntARGB);
    imgBox.add(imgCustomRGBA);
    imgBox.add(imgCustomRGB);

    javax.swing.Box topBox = new javax.swing.Box(BoxLayout.X_AXIS);
    topBox.add(flipBox);
    topBox.add(texBox);
    topBox.add(geomBox);
    topBox.add(yBox);
    Component strut = topBox.createRigidArea(new Dimension(10, 10));
    topBox.add(strut);
    topBox.add(imgBox);

    frameDelay = new JSlider(0, 50, 0);
    frameDelay.addChangeListener(this);
    frameDelay.setSnapToTicks(true);
    frameDelay.setPaintTicks(true);
    frameDelay.setPaintLabels(true);
    frameDelay.setMajorTickSpacing(10);
    frameDelay.setMinorTickSpacing(1);
    frameDelay.setValue(20);
    JLabel delayL = new JLabel("frame delay");
    javax.swing.Box delayBox = new javax.swing.Box(BoxLayout.X_AXIS);
    delayBox.add(delayL);
    delayBox.add(frameDelay);

    animationB = new JButton(" stop animation ");
    animationB.addActionListener(this);

    JLabel texInfo1 = new JLabel("*To use ImageComponent by reference feature, use TYPE_4BYTE_ABGR on Solaris");
    JLabel texInfo2 = new JLabel("and TYPE_3BYTE_BGR on Windows");

    JPanel buttonP = new JPanel();
    GridBagLayout gridbag = new GridBagLayout();
    GridBagConstraints c = new GridBagConstraints();
    buttonP.setLayout(gridbag);
    c.anchor = GridBagConstraints.CENTER;
    c.gridwidth = GridBagConstraints.REMAINDER;
    gridbag.setConstraints(topBox, c);
    buttonP.add(topBox);
    gridbag.setConstraints(delayBox, c);
    buttonP.add(delayBox);
    gridbag.setConstraints(animationB, c);
    buttonP.add(animationB);
    gridbag.setConstraints(texInfo1, c);
    buttonP.add(texInfo1);
    gridbag.setConstraints(texInfo2, c);
    buttonP.add(texInfo2);

    return buttonP;

}

From source file:org.championship.manager.license.LicenseDialog.java

public LicenseDialog(Frame owner) throws HeadlessException {
    super(owner, "License", true);

    setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));

    JScrollPane scrollPane = new JScrollPane(new LicenseEditorPane());
    scrollPane.setAlignmentX(Component.CENTER_ALIGNMENT);
    add(scrollPane);/*from www  .  j  a va 2s  .  co m*/

    JButton close = new JButton("Schlieen");
    close.addActionListener(new ActionListener() {

        /**
         * {@inheritDoc}
         */
        public void actionPerformed(ActionEvent e) {
            LicenseDialog.this.dispose();
        }
    });

    add(Box.createRigidArea(new Dimension(0, 5)));

    close.setAlignmentX(Component.CENTER_ALIGNMENT);
    add(close);

    prepareSize();

    ComponentUtilities.centerComponentOnScreen(this);

    setVisible(true);
}

From source file:unikn.dbis.univis.explorer.license.LicenseDialog.java

public LicenseDialog(Frame owner) throws HeadlessException {
    super(owner, "License", true);

    setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));

    JScrollPane scrollPane = new JScrollPane(new LicenseEditorPane());
    scrollPane.setAlignmentX(Component.CENTER_ALIGNMENT);
    add(scrollPane);//from w w  w  .j a v  a 2  s . c  o m

    JButton close = new JButton(MessageResolver.getMessage(Constants.CLOSE));
    close.addActionListener(new ActionListener() {

        /**
         * {@inheritDoc}
         */
        public void actionPerformed(ActionEvent e) {
            LicenseDialog.this.dispose();
        }
    });

    add(Box.createRigidArea(new Dimension(0, 5)));

    close.setAlignmentX(Component.CENTER_ALIGNMENT);
    add(close);

    prepareSize();

    ComponentUtilities.centerComponentOnScreen(this);

    setVisible(true);
}

From source file:com.opendoorlogistics.components.reports.ReporterPanel.java

public ReporterPanel(final ComponentConfigurationEditorAPI api, final ReporterConfig config) {
    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
    // setAlignmentX(LEFT_ALIGNMENT);

    // add config panel
    ReporterConfigPanel configPanel = new ReporterConfigPanel(config);
    configPanel.setBorder(createBorder("Export and processing options"));
    add(configPanel);//www.  j a  va2  s  .c om

    // add gap
    add(Box.createRigidArea(new Dimension(1, 10)));

    // add tools panel
    JPanel toolContainer = new JPanel();
    toolContainer.setLayout(new BorderLayout());
    toolContainer.setBorder(createBorder("Tools"));

    add(toolContainer);

    JPanel tools = new JPanel();
    toolContainer.add(tools, BorderLayout.NORTH);
    toolContainer.setMaximumSize(new Dimension(Integer.MAX_VALUE, api.isInstruction() ? 120 : 80));
    // tools.setLayout(new BoxLayout(tools, BoxLayout.X_AXIS));
    tools.setLayout(new GridLayout(api == null || api.isInstruction() ? 2 : 1, 3));
    JButton compileButton = new JButton("Compile .jrxml file");
    compileButton.setToolTipText("Compile a JasperReports .jrxml file");
    compileButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            File file = ReporterTools.chooseJRXMLFile(api.getComponentPreferences(), LAST_JRXML_TO_COMPILE,
                    ReporterPanel.this);
            if (file == null) {
                return;
            }

            final ExecutionReport report = api.getApi().uiFactory().createExecutionReport();
            try {
                JasperDesign design = JRXmlLoader.load(file);
                if (design == null) {
                    throw new RuntimeException("File to load jrxml: " + file.getAbsolutePath());
                }

                String filename = FilenameUtils.removeExtension(file.getAbsolutePath()) + ".jasper";
                JasperCompileManager.compileReportToFile(design, filename);
            } catch (Throwable e2) {
                report.setFailed(e2);
                report.setFailed("Failed to compile file " + file.getAbsolutePath());
            } finally {
                if (report.isFailed()) {
                    Window window = SwingUtilities.getWindowAncestor(ReporterPanel.this);
                    api.getApi().uiFactory()
                            .createExecutionReportDialog(
                                    JFrame.class.isInstance(window) ? (JFrame) window : null,
                                    "Compiling jrxml file", report, true)
                            .setVisible(true);
                } else {
                    JOptionPane.showMessageDialog(ReporterPanel.this,
                            "Compiled jxrml successfully: " + file.getAbsolutePath());
                }
            }
        }
    });
    tools.add(compileButton);

    for (final OrientationEnum orientation : new OrientationEnum[] { OrientationEnum.LANDSCAPE,
            OrientationEnum.PORTRAIT }) {
        // create export button
        JButton button = new JButton("Export " + orientation.getName().toLowerCase() + " template");
        button.setToolTipText(
                "Export template (editable .jrxml and compiled .jasper) based on the input tables ("
                        + orientation.getName().toLowerCase() + ")");
        button.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                ReporterTools.exportReportTemplate(api, config, orientation, ReporterPanel.this);
            }
        });
        tools.add(button);

        // create view button
        if (api.isInstruction()) {
            final String title = "View basic " + orientation.getName().toLowerCase() + " report";
            button = new JButton(title);
            button.setToolTipText("View basic report based on the input tables ("
                    + orientation.getName().toLowerCase() + ")");
            button.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    if (api != null) {
                        api.executeInPlace(title,
                                orientation == OrientationEnum.LANDSCAPE
                                        ? ReporterComponent.VIEW_BASIC_LANDSCAPE
                                        : ReporterComponent.VIEW_BASIC_PORTRAIT);
                    }
                }
            });
            tools.add(button);
        }
    }

}

From source file:Main.java

public Main() {
    setSize(500, 340);/* w w  w.  j  a v a  2  s.c  o m*/

    Date currentDate = new Date();
    calendar.setTime(currentDate);

    JPanel p1 = new JPanel();
    p1.setLayout(new GridLayout(4, 1));

    JPanel p = new JPanel();
    p.setBorder(new TitledBorder(new EtchedBorder(), "Selected Date"));
    dateLabel = new JLabel(dateFormat.format(currentDate) + "     ");
    dateLabel.setFont(new Font("Arial", Font.BOLD, 24));
    p.add(dateLabel);
    p1.add(p);

    yearSlider.setPaintLabels(true);
    yearSlider.setMajorTickSpacing(5);
    yearSlider.setMinorTickSpacing(1);
    yearSlider.setPaintTicks(true);
    DateListener lst = new DateListener();
    yearSlider.addChangeListener(lst);

    p = new JPanel();
    p.setBorder(new TitledBorder(new EtchedBorder(), "Year"));
    p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
    p.add(Box.createRigidArea(RIGID_DIMENSION));
    p.add(yearSlider);
    p.add(Box.createRigidArea(RIGID_DIMENSION));
    p1.add(p);

    String[] months = (new DateFormatSymbols()).getShortMonths();
    hashTable = new Hashtable(12);
    for (int i = 0; i < 12; i++)
        hashTable.put(new Integer(i + 1), new JLabel(months[i], JLabel.CENTER));
    monthSlider.setLabelTable(hashTable);
    monthSlider.setPaintLabels(true);
    monthSlider.setMajorTickSpacing(1);
    monthSlider.setPaintTicks(true);
    monthSlider.addChangeListener(lst);

    p = new JPanel();
    p.setBorder(new TitledBorder(new EtchedBorder(), "Month"));
    p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
    p.add(Box.createRigidArea(RIGID_DIMENSION));
    p.add(monthSlider);
    p.add(Box.createRigidArea(RIGID_DIMENSION));
    p1.add(p);

    int maxDays = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
    daySlider = new JSlider(JSlider.HORIZONTAL, 1, maxDays, calendar.get(Calendar.DAY_OF_MONTH));
    daySlider.setPaintLabels(true);
    daySlider.setMajorTickSpacing(5);
    daySlider.setMinorTickSpacing(1);
    daySlider.setPaintTicks(true);
    daySlider.addChangeListener(lst);

    p = new JPanel();
    p.setBorder(new TitledBorder(new EtchedBorder(), "Day"));
    p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
    p.add(Box.createRigidArea(RIGID_DIMENSION));
    p.add(daySlider);
    p.add(Box.createRigidArea(RIGID_DIMENSION));
    p1.add(p);

    getContentPane().add(p1, BorderLayout.CENTER);

    WindowListener wndCloser = new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    };
    addWindowListener(wndCloser);

    enableEvents(ComponentEvent.COMPONENT_RESIZED);
    setVisible(true);
}

From source file:com.opendoorlogistics.speedregions.excelshp.app.FileBrowserPanel.java

public FileBrowserPanel(int indentWidth, String label, String initialFilename,
        final Consumer<String> filenameChangeListener, final boolean directoriesOnly,
        final String browserApproveButtonText, final FileFilter... fileFilters) {

    textField = createTextField(initialFilename, filenameChangeListener);

    // add browser button
    browseButton = createBrowseButton(directoriesOnly, browserApproveButtonText, textField, fileFilters);

    setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
    if (indentWidth > 0) {
        add(Box.createRigidArea(new Dimension(indentWidth, 1)));
    }/*from  w ww. j a va2  s  . co m*/
    if (label != null) {
        this.label = new JLabel(label);
        add(this.label);
    } else {
        this.label = null;
    }
    add(textField);
    add(browseButton);
}

From source file:components.ListDialogRunner.java

public static JPanel createUI() {
    //Create the labels.
    JLabel intro = new JLabel("The chosen name:");
    final JLabel name = new JLabel(names[1]);
    intro.setLabelFor(name);/*from  w  w w  .j  a  v  a 2  s  .  c  om*/

    //Use a wacky font if it exists. If not, this falls
    //back to a font we know exists.
    name.setFont(getAFont());

    //Create the button.
    final JButton button = new JButton("Pick a new name...");
    button.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            String selectedName = ListDialog.showDialog(frame, button, "Baby names ending in O:",
                    "Name Chooser", names, name.getText(), "Cosmo  ");
            name.setText(selectedName);
        }
    });

    //Create the panel we'll return and set up the layout.
    JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));
    panel.setBorder(BorderFactory.createEmptyBorder(20, 20, 10, 20));
    intro.setAlignmentX(JComponent.CENTER_ALIGNMENT);
    name.setAlignmentX(JComponent.CENTER_ALIGNMENT);
    button.setAlignmentX(JComponent.CENTER_ALIGNMENT);

    //Add the labels to the content pane.
    panel.add(intro);
    panel.add(Box.createVerticalStrut(5)); //extra space
    panel.add(name);

    //Add a vertical spacer that also guarantees us a minimum width:
    panel.add(Box.createRigidArea(new Dimension(150, 10)));

    //Add the button.
    panel.add(button);

    return panel;
}

From source file:eu.apenet.dpt.standalone.gui.XsltAdderActionListener.java

public void actionPerformed(ActionEvent e) {
    JFileChooser xsltChooser = new JFileChooser();
    xsltChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);

    if (xsltChooser.showOpenDialog(parent) == JFileChooser.APPROVE_OPTION) {
        File file = xsltChooser.getSelectedFile();
        if (isXSLT(file)) {
            if (saveXslt(file)) {
                JRadioButton newButton = new JRadioButton(file.getName());
                newButton.addActionListener(new XsltSelectorListener(dataPreparationToolGUI));
                dataPreparationToolGUI.getGroupXslt().add(newButton);
                dataPreparationToolGUI.getAPEPanel().getApeTabbedPane().addToXsltPanel(newButton);
                dataPreparationToolGUI.getAPEPanel().getApeTabbedPane()
                        .addToXsltPanel(Box.createRigidArea(new Dimension(0, 10)));
                JOptionPane.showMessageDialog(parent, labels.getString("xsltSaved") + ".",
                        labels.getString("fileSaved"), JOptionPane.INFORMATION_MESSAGE, Utilities.icon);
            } else {
                JOptionPane.showMessageDialog(parent, labels.getString("xsltNotSaved") + ".",
                        labels.getString("fileNotSaved"), JOptionPane.ERROR_MESSAGE, Utilities.icon);
            }//from w  w  w . j av a2 s  . c  om
        } else {
            JOptionPane.showMessageDialog(parent, labels.getString("xsltNotSaved") + ".",
                    labels.getString("fileNotSaved"), JOptionPane.ERROR_MESSAGE, Utilities.icon);
        }
    }
}

From source file:com.opendoorlogistics.core.utils.ui.FileBrowserPanel.java

private FileBrowserPanel(int indentWidth, String label, String initialFilename,
        final FilenameChangeListener filenameChangeListener, final boolean directoriesOnly,
        final String browserApproveButtonText, final FileFilter... fileFilters) {

    textField = createTextField(initialFilename, filenameChangeListener);

    // add browser button
    browseButton = createBrowseButton(directoriesOnly, browserApproveButtonText, textField, fileFilters);

    setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
    if (indentWidth > 0) {
        add(Box.createRigidArea(new Dimension(indentWidth, 1)));
    }//from ww  w .j  av a2s.c  o m
    if (label != null) {
        this.label = new JLabel(label);
        add(this.label);
    } else {
        this.label = null;
    }
    add(textField);
    add(browseButton);
}