Example usage for java.awt FlowLayout FlowLayout

List of usage examples for java.awt FlowLayout FlowLayout

Introduction

In this page you can find the example usage for java.awt FlowLayout FlowLayout.

Prototype

public FlowLayout() 

Source Link

Document

Constructs a new FlowLayout with a centered alignment and a default 5-unit horizontal and vertical gap.

Usage

From source file:com.intel.stl.ui.common.view.DistributionPiePanel.java

public void setLabels(String[] itemNames, ImageIcon[] icons, int labelColumns) {
    if (icons.length != itemNames.length) {
        throw new IllegalArgumentException(
                "Inconsistent number of items. " + " itemNames=" + itemNames.length + " icons=" + icons.length);
    }//from w  ww .  java2s  .c o m

    labels = new JLabel[icons.length];
    for (int i = 0; i < icons.length; i++) {
        labels[i] = new JLabel(itemNames[i], icons[i], JLabel.LEFT);
    }

    int rows = 1;
    if (labelColumns <= 0) {
        labelPanel.setLayout(new FlowLayout());
        for (JLabel label : labels) {
            labelPanel.add(label);
        }
    } else {
        BoxLayout layout = new BoxLayout(labelPanel, BoxLayout.X_AXIS);
        labelPanel.setLayout(layout);
        JPanel[] columns = new JPanel[labelColumns];
        for (int i = 0; i < columns.length; i++) {
            labelPanel.add(Box.createHorizontalGlue());
            columns[i] = new JPanel();
            columns[i].setOpaque(false);
            columns[i].setBorder(BorderFactory.createEmptyBorder(2, 3, 2, 3));
            BoxLayout cLayout = new BoxLayout(columns[i], BoxLayout.Y_AXIS);
            columns[i].setLayout(cLayout);
            labelPanel.add(columns[i]);
        }
        labelPanel.add(Box.createHorizontalGlue());
        rows = (int) Math.ceil((double) labels.length / labelColumns);
        int index = 0;
        for (int i = 0; i < rows; i++) {
            for (int j = 0; j < labelColumns; j++) {
                columns[i].add(index < labels.length ? labels[index] : Box.createGlue());
                index += 1;
            }
        }
    }
}

From source file:es.emergya.ui.gis.popups.SaveGPXDialog.java

private SaveGPXDialog(final List<Layer> capas) {
    super("Consulta de Posiciones GPS");
    setResizable(false);// w  w  w . j  av a 2s  . c  om
    setAlwaysOnTop(true);
    try {
        setIconImage(((BasicWindow) GoClassLoader.getGoClassLoader().load(BasicWindow.class)).getFrame()
                .getIconImage());
    } catch (Throwable e) {
        LOG.error("There is no icon image", e);
    }

    this.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
    JPanel dialogo = new JPanel(new BorderLayout());
    dialogo.setBackground(Color.WHITE);
    dialogo.setBorder(new EmptyBorder(10, 10, 10, 10));

    JPanel central = new JPanel(new FlowLayout());
    central.setOpaque(false);
    final JTextField nombre = new JTextField(15);
    nombre.setEditable(false);
    central.add(nombre);
    final JButton button = new JButton("Examinar...", LogicConstants.getIcon("button_nuevo"));
    central.add(button);
    final JButton aceptar = new JButton("Guardar", LogicConstants.getIcon("button_save"));
    button.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            JFileChooser fileChooser = new JFileChooser();
            if (fileChooser.showSaveDialog(SaveGPXDialog.this) == JFileChooser.APPROVE_OPTION) {
                nombre.setText(fileChooser.getSelectedFile().getAbsolutePath());
                aceptar.setEnabled(true);
            }
        }
    });

    dialogo.add(central, BorderLayout.CENTER);

    JPanel botones = new JPanel(new FlowLayout());
    botones.setOpaque(false);

    aceptar.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            String base_url = nombre.getText() + "_";
            for (Layer layer : capas) {
                if (layer instanceof GpxLayer) {
                    GpxLayer gpxLayer = (GpxLayer) layer;
                    File f = new File(base_url + gpxLayer.name + ".gpx");

                    boolean sobreescribir = !f.exists();

                    try {
                        while (!sobreescribir) {
                            String original = f.getCanonicalPath();
                            f = checkFileOverwritten(nombre, f);
                            sobreescribir = !f.exists() || original.equals(f.getCanonicalPath());
                        }
                    } catch (NullPointerException t) {
                        log.debug("Cancelando creacion de fichero: " + t);
                        sobreescribir = false;
                    } catch (Throwable t) {
                        log.error("Error comprobando la sobreescritura", t);
                        sobreescribir = false;
                    }

                    if (sobreescribir) {
                        try {
                            f.createNewFile();
                        } catch (IOException e1) {
                            log.error(e1, e1);
                        }
                        if (!(f.isFile() && f.canWrite()))
                            JOptionPane.showMessageDialog(SaveGPXDialog.this,
                                    "No tengo permiso para escribir en " + f.getAbsolutePath());
                        else {
                            try {
                                OutputStream out = new FileOutputStream(f);
                                GpxWriter writer = new GpxWriter(out);
                                writer.write(gpxLayer.data);
                                out.close();
                            } catch (Throwable t) {
                                log.error("Error al escribir el gpx", t);
                                JOptionPane.showMessageDialog(SaveGPXDialog.this,
                                        "Ocurri un error al escribir en " + f.getAbsolutePath());
                            }
                        }
                    } else
                        log.error("Por errores anteriores no se escribio el fichero");
                } else
                    log.error("Una de las capas no era gpx: " + layer.name);
            }
            SaveGPXDialog.this.dispose();

        }

        private File checkFileOverwritten(final JTextField nombre, File f) throws Exception {
            String nueva = JOptionPane.showInputDialog(nombre, i18n.getString("savegpxdialog.overwrite"),
                    "Sobreescribir archivo", JOptionPane.QUESTION_MESSAGE, null, null, f.getCanonicalPath())
                    .toString();
            log.debug("Nueva ruta: " + nueva);
            return new File(nueva);
        }
    });

    JButton cancelar = new JButton("Cancelar", LogicConstants.getIcon("button_cancel"));

    cancelar.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            SaveGPXDialog.this.dispose();
        }
    });

    aceptar.setEnabled(false);
    botones.add(aceptar);
    botones.add(cancelar);
    dialogo.add(botones, BorderLayout.SOUTH);

    add(dialogo);
    setPreferredSize(new Dimension(300, 200));
    pack();

    int x;
    int y;

    Container myParent;
    try {
        myParent = ((BasicWindow) GoClassLoader.getGoClassLoader().load(BasicWindow.class)).getFrame()
                .getContentPane();
        java.awt.Point topLeft = myParent.getLocationOnScreen();
        Dimension parentSize = myParent.getSize();

        Dimension mySize = getSize();

        if (parentSize.width > mySize.width)
            x = ((parentSize.width - mySize.width) / 2) + topLeft.x;
        else
            x = topLeft.x;

        if (parentSize.height > mySize.height)
            y = ((parentSize.height - mySize.height) / 2) + topLeft.y;
        else
            y = topLeft.y;

        setLocation(x, y);
    } catch (Throwable e1) {
        LOG.error("There is no basic window!", e1);
    }

    this.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosed(WindowEvent e) {
            nombre.setText("");
            nombre.repaint();
        }

        @Override
        public void windowClosing(WindowEvent e) {
            nombre.setText("");
            nombre.repaint();
        }
    });
}

From source file:MainProgram.MainProgram.java

public MainFrame() throws InterruptedException {
    super("Registration automator");
    setLayout(new FlowLayout());
    MainFrameProgram MainFrame = new MainFrameProgram();
    setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("power-icon.png")));
    MainFrame.setPreferredSize(new Dimension(420, 215));
    Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
    setLocation(dim.width - this.getSize().width - 1250, dim.height / 5 - this.getSize().height);
    add(MainFrame);/*from www  .  jav  a  2s  .  co  m*/
    logFrameInitializer();
}

From source file:net.sf.jhylafax.AbstractQueuePanel.java

public AbstractQueuePanel(String queueName) {
    this.queueName = queueName;

    setLayout(new BorderLayout());
    setBorder(GUIHelper.createEmptyBorder(10));

    resetQueueTableAction = new ResetQueueTableAction();

    tablePopupMenu = new JPopupMenu();

    TableSorter sorter = new TableSorter(getTableModel());
    queueTable = new ColoredTable(sorter);
    queueTableLayout = new TableLayout(queueTable);
    initializeTableLayout();//from   ww  w .  ja  v  a  2s  . c  o  m
    queueTableLayout.getHeaderPopupMenu().add(new JMenuItem(resetQueueTableAction));
    add(new JScrollPane(queueTable), BorderLayout.CENTER);

    queueTable.setShowVerticalLines(true);
    queueTable.setShowHorizontalLines(false);
    queueTable.setAutoCreateColumnsFromModel(true);
    queueTable.setIntercellSpacing(new java.awt.Dimension(2, 1));
    queueTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    queueTable.getSelectionModel().addListSelectionListener(this);
    queueTable.addMouseListener(new PopupListener(tablePopupMenu));

    queueTable.setDefaultRenderer(Long.class, new FilesizeCellRenderer());
    queueTable.setDefaultRenderer(String.class, new StringCellRenderer());
    queueTable.setDefaultRenderer(Date.class, new TimeCellRenderer());
    queueTable.setDefaultRenderer(FaxJob.State.class, new StateCellRenderer());

    buttonPanel = new JPanel(new FlowLayout());
    add(buttonPanel, BorderLayout.SOUTH);
}

From source file:gui.images.CodebookVectorProfilePanel.java

/**
 * Sets the data to be shown.//  ww  w  .jav a  2s  .co  m
 *
 * @param occurrenceProfile Double array that is the neighbor occurrence
 * profile of this visual word.
 * @param codebookIndex Integer that is the index of this visual word.
 * @param classColors Color[] of class colors.
 * @param classNames String[] of class names.
 */
public void setResults(double[] occurrenceProfile, int codebookIndex, Color[] classColors,
        String[] classNames) {
    int numClasses = Math.min(classNames.length, occurrenceProfile.length);
    this.codebookIndex = codebookIndex;
    this.occurrenceProfile = occurrenceProfile;
    DefaultPieDataset pieData = new DefaultPieDataset();
    for (int cIndex = 0; cIndex < numClasses; cIndex++) {
        pieData.setValue(classNames[cIndex], occurrenceProfile[cIndex]);
    }
    JFreeChart chart = ChartFactory.createPieChart3D("codebook vect " + codebookIndex, pieData, true, true,
            false);
    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setDirection(Rotation.CLOCKWISE);
    plot.setForegroundAlpha(0.5f);
    PieRenderer prend = new PieRenderer(classColors);
    prend.setColor(plot, pieData);
    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new Dimension(140, 140));
    chartPanel.setVisible(true);
    chartPanel.revalidate();
    chartPanel.repaint();
    JPanel jp = new JPanel();
    jp.setPreferredSize(new Dimension(140, 140));
    jp.setMinimumSize(new Dimension(140, 140));
    jp.setMaximumSize(new Dimension(140, 140));
    jp.setSize(new Dimension(140, 140));
    jp.setLayout(new FlowLayout());
    jp.add(chartPanel);
    jp.setVisible(true);
    jp.validate();
    jp.repaint();

    JFrame frame = new JFrame();
    frame.setBackground(Color.WHITE);
    frame.setUndecorated(true);
    frame.getContentPane().add(jp);
    frame.pack();
    BufferedImage bi = new BufferedImage(jp.getWidth(), jp.getHeight(), BufferedImage.TYPE_INT_ARGB);
    Graphics2D graphics = bi.createGraphics();
    jp.print(graphics);
    graphics.dispose();
    frame.dispose();
    imPanel.removeAll();
    imPanel.setImage(bi);
    imPanel.setVisible(true);
    imPanel.revalidate();
    imPanel.repaint();
}

From source file:br.com.criativasoft.opendevice.samples.ui.SimpleChart.java

public SimpleChart(final String title, final StreamConnection connection) {
    super(title);

    dataset = new DynamicTimeSeriesCollection(SERIES, COUNT, new Second());
    dataset.setTimeBase(new Second(0, 0, 0, 1, 1, Calendar.getInstance().get(Calendar.YEAR)));

    // Init./*  w ww  . java2  s. c  om*/
    //        for (int i = 0; i < SERIES; i++){
    //            dataset.addSeries(new float[]{0}, i, "Serie " + (i+1));
    //        }
    dataset.addSeries(new float[] { 0, 0, 0 }, 0, "Raw");
    dataset.addSeries(new float[] { 0, 0, 0 }, 1, "Software");
    dataset.addSeries(new float[] { 0, 0, 0 }, 2, "Hardware");

    this.connection = connection;

    // connection.setStreamReader(new FixedStreamReader(1));

    JFreeChart chart = createChart(dataset);

    final JButton run = new JButton(START);
    run.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {

            String cmd = e.getActionCommand();
            JButton source = (JButton) e.getSource();

            try {

                if (cmd.equals(START)) {
                    connection.addListener(SimpleChart.this);
                    if (!connection.isConnected())
                        connection.connect();

                    source.setText(STOP);
                    source.setActionCommand(STOP);
                } else {
                    connection.removeListener(SimpleChart.this);
                    source.setText(START);
                    source.setActionCommand(START);
                }

            } catch (ConnectionException e1) {
                e1.printStackTrace();
            }

        }
    });

    final JComboBox combo = new JComboBox();

    if (connection instanceof UsbConnection) {

        Collection<String> portNames = UsbConnection.listAvailablePortNames();
        for (String name : portNames) {
            combo.addItem(name);
        }

    }

    combo.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {

            Object selectedItem = combo.getSelectedItem();

        }
    });

    this.add(new ChartPanel(chart), BorderLayout.CENTER);
    JPanel btnPanel = new JPanel(new FlowLayout());
    btnPanel.add(run);
    btnPanel.add(combo);
    this.add(btnPanel, BorderLayout.SOUTH);

}

From source file:org.ietr.preesm.mapper.ui.BestCostPlotter.java

/**
 * Constructs the latency plotter/*from www . ja v a  2s .  co  m*/
 * 
 * @param title
 *            the frame title.
 */
public BestCostPlotter(final String title, Semaphore pauseSemaphore) {

    super(title);

    JFreeChart chart = createChart(title);
    final JPanel content = new JPanel(new BorderLayout());

    chartPanel = new ChartPanel(chart);
    content.add(chartPanel);

    final JPanel buttonPanel = new JPanel(new FlowLayout());

    final JButton buttonPause = new JButton("Pause");
    buttonPause.setActionCommand("pause");
    buttonPause.addActionListener(this);
    buttonPanel.add(buttonPause);

    final JButton buttonAll = new JButton("Stop");
    buttonAll.setActionCommand("ADD_ALL");
    buttonAll.addActionListener(this);
    buttonPanel.add(buttonAll);

    final JButton buttonLecture = new JButton("Resume");
    buttonLecture.setActionCommand("Resume");
    buttonLecture.addActionListener(this);
    buttonPanel.add(buttonLecture);

    content.add(buttonPanel, BorderLayout.SOUTH);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 470));
    chartPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    setContentPane(content);

    this.pauseSemaphore = pauseSemaphore;
}

From source file:gtu._work.ui.StringArrayMakerUI.java

private void initGUI() {
    try {/*from w  w w .j  a va2s . c o  m*/
        BorderLayout thisLayout = new BorderLayout();
        setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        getContentPane().setLayout(thisLayout);
        {
            jTabbedPane1 = new JTabbedPane();
            getContentPane().add(jTabbedPane1, BorderLayout.CENTER);
            {
                jPanel1 = new JPanel();
                BorderLayout jPanel1Layout = new BorderLayout();
                jPanel1.setLayout(jPanel1Layout);
                jTabbedPane1.addTab("jPanel1", null, jPanel1, null);
                {
                    jScrollPane2 = new JScrollPane();
                    jPanel1.add(jScrollPane2, BorderLayout.CENTER);
                    jScrollPane2.setPreferredSize(new java.awt.Dimension(525, 267));
                    {
                        ListModel jList1Model = new DefaultListModel();
                        jList1 = new JList();

                        jScrollPane2.setViewportView(jList1);
                        jList1.addKeyListener(new KeyAdapter() {
                            public void keyPressed(KeyEvent evt) {
                                JListUtil.newInstance(jList1).defaultJListKeyPressed(evt);
                            }
                        });
                        jList1.setModel(jList1Model);
                    }
                }
                {
                    jButton1 = new JButton();
                    jPanel1.add(jButton1, BorderLayout.NORTH);
                    jButton1.setText("\u8cbc\u4e0a");
                    jButton1.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            jButton1ActionPerformed(evt);
                        }
                    });
                }
                {
                    jPanel3 = new JPanel();
                    FlowLayout jPanel3Layout = new FlowLayout();
                    jPanel3Layout.setAlignment(FlowLayout.RIGHT);
                    jPanel1.add(jPanel3, BorderLayout.WEST);
                    jPanel3.setLayout(jPanel3Layout);
                    jPanel3.setPreferredSize(new java.awt.Dimension(50, 291));
                    {
                        jCheckBox1 = new JCheckBox();
                        jPanel3.add(jCheckBox1);
                        jCheckBox1.setText("\\n");
                    }
                    {
                        jCheckBox2 = new JCheckBox();
                        jPanel3.add(jCheckBox2);
                        jCheckBox2.setText("\\t");
                    }
                }
            }
            {
                jPanel2 = new JPanel();
                BorderLayout jPanel2Layout = new BorderLayout();
                jPanel2.setLayout(jPanel2Layout);
                jTabbedPane1.addTab("jPanel2", null, jPanel2, null);
                {
                    jButton2 = new JButton();
                    jPanel2.add(jButton2, BorderLayout.NORTH);
                    jButton2.setText("\u7522\u751f");
                    jButton2.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            jButton2ActionPerformed(evt);
                        }
                    });
                }
                {
                    jScrollPane1 = new JScrollPane();
                    jPanel2.add(jScrollPane1, BorderLayout.CENTER);
                    jScrollPane1.setPreferredSize(new java.awt.Dimension(525, 291));
                    {
                        jTextArea1 = new JTextArea();
                        jScrollPane1.setViewportView(jTextArea1);
                        jTextArea1.setText("");
                    }
                }
            }
        }
        pack();
        this.setSize(546, 382);
    } catch (Exception e) {
        // add your error handling code here
        e.printStackTrace();
    }
}

From source file:de.codesourcery.jasm16.ide.ui.utils.UIUtils.java

/**
 * // w  w  w.  j  av a 2 s  .  c  om
 * @param parent
 * @param title
 * @param message
 * @return <code>true</code> if project should also be physically deleted,
 * <code>false</code> is project should be deleted but all files should be left alone,
 * <code>null</code> if user cancelled the dialog/project should not be deleted
 */
public static Boolean showDeleteProjectDialog(IAssemblyProject project) {
    final JDialog dialog = new JDialog((Window) null, "Delete project " + project.getName());

    dialog.setModal(true);

    final JTextArea message = createMultiLineLabel(
            "Do you really want to delete project '" + project.getName() + " ?");
    final JCheckBox checkbox = new JCheckBox("Delete project files");

    final DialogResult[] outcome = { DialogResult.CANCEL };

    final JButton yesButton = new JButton("Yes");
    yesButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            outcome[0] = DialogResult.YES;
            dialog.dispose();
        }
    });

    final JButton noButton = new JButton("No");
    noButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            outcome[0] = DialogResult.NO;
            dialog.dispose();
        }
    });
    final JButton cancelButton = new JButton("Cancel");
    cancelButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            outcome[0] = DialogResult.CANCEL;
            dialog.dispose();
        }
    });

    final JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new FlowLayout());
    buttonPanel.add(yesButton);
    buttonPanel.add(noButton);
    buttonPanel.add(cancelButton);

    final JPanel messagePanel = new JPanel();
    messagePanel.setLayout(new GridBagLayout());

    GridBagConstraints cnstrs = constraints(0, 0, true, false, GridBagConstraints.NONE);
    cnstrs.gridwidth = GridBagConstraints.REMAINDER;
    cnstrs.weighty = 0;
    cnstrs.gridheight = 1;
    messagePanel.add(message, cnstrs);

    cnstrs = constraints(0, 1, true, true, GridBagConstraints.NONE);
    cnstrs.gridwidth = GridBagConstraints.REMAINDER;
    cnstrs.gridheight = 1;
    cnstrs.weighty = 0;
    messagePanel.add(checkbox, cnstrs);

    final JPanel panel = new JPanel();
    panel.setLayout(new GridBagLayout());

    cnstrs = constraints(0, 0, true, false, GridBagConstraints.NONE);
    cnstrs.gridwidth = GridBagConstraints.REMAINDER;
    cnstrs.gridheight = 1;
    cnstrs.weighty = 0;
    cnstrs.insets = new Insets(5, 2, 5, 2); // top,left,bottom,right         
    panel.add(messagePanel, cnstrs);

    cnstrs = constraints(0, 1, true, true, GridBagConstraints.HORIZONTAL);
    cnstrs.gridwidth = GridBagConstraints.REMAINDER;
    cnstrs.gridheight = 1;
    cnstrs.weighty = 0;
    cnstrs.insets = new Insets(0, 2, 10, 2); // top,left,bottom,right      
    panel.add(buttonPanel, cnstrs);

    dialog.getContentPane().add(panel);
    dialog.pack();
    dialog.setVisible(true);

    if (outcome[0] != DialogResult.YES) {
        return null;
    }
    return checkbox.isSelected();
}

From source file:com.k42b3.aletheia.response.html.Images.java

public Images() {
    super();//from w  w w. j a v a  2 s . com

    executorService = Executors.newFixedThreadPool(6);

    // settings
    this.setTitle("Images");
    this.setLocation(100, 100);
    this.setPreferredSize(new Dimension(360, 600));
    this.setMinimumSize(this.getSize());
    this.setResizable(false);
    this.setLayout(new BorderLayout());

    // list
    model = new DefaultListModel<URL>();
    list = new JList<URL>(model);
    list.addListSelectionListener(new ListSelectionListener() {

        public void valueChanged(ListSelectionEvent e) {
            btnDownload.setEnabled(list.getSelectedIndex() != -1);
        }

    });
    list.setCellRenderer(new ImageCellRenderer());

    scp = new JScrollPane(list);
    scp.setBorder(new EmptyBorder(4, 4, 4, 4));

    this.add(scp, BorderLayout.CENTER);

    // buttons
    JPanel panelButtons = new JPanel();

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

    panelButtons.setLayout(fl);

    btnDownload = new JButton("Download");
    btnDownload.addActionListener(new DownloadHandler());
    btnDownload.setEnabled(false);
    JButton btnCancel = new JButton("Cancel");
    btnCancel.addActionListener(new CloseHandler());
    lblInfo = new JLabel("");

    panelButtons.add(btnDownload);
    panelButtons.add(btnCancel);
    panelButtons.add(lblInfo);

    this.add(panelButtons, BorderLayout.SOUTH);

    this.pack();
}