Example usage for java.awt GridLayout GridLayout

List of usage examples for java.awt GridLayout GridLayout

Introduction

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

Prototype

public GridLayout(int rows, int cols) 

Source Link

Document

Creates a grid layout with the specified number of rows and columns.

Usage

From source file:de.weltraumschaf.minesweeper.gui.MineFieldPanel.java

/**
 * Dedicated constructor.//w w w . jav a  2s. c  om
 *
 * @param width must not be less than 1
 * @param height must not be less than 1
 * @param main must not be {@code null}
 */
public MineFieldPanel(int width, int height, final MainWindow main) {
    super(new GridLayout(width, height));
    this.fieldButtons = new Matrix<FieldBoxButton>(FieldBoxButton.class, width, height);
    this.width = width;
    this.height = height;
    Validate.notNull(main, "Main must not be null!");
    this.main = main;
}

From source file:ArcApp.java

public ArcApp() {
    super(new BorderLayout());
    canvas = new MyCanvas();
    int width = 600;
    int height = 55;
    sliderX = setSlider(0, width, width / 4, width / 2, width / 4);
    sliderY = setSlider(0, height, height / 4, height / 2, height / 4);
    sliderWidth = setSlider(0, width, width / 2, width / 2, width / 4);
    sliderHeight = setSlider(0, height, height / 2, height / 2, height / 4);
    sliderT0 = setSlider(0, 360, 45, 180, 45);
    sliderT = setSlider(0, 360, 135, 180, 45);

    JPanel panel1 = new JPanel();
    panel1.setLayout(new GridLayout(3, 3));
    panel1.add(new JLabel("Location (x,y): ", JLabel.RIGHT));
    panel1.add(sliderX);/*from  w  ww  .  j av  a 2 s  . c  om*/
    panel1.add(sliderY);
    panel1.add(new JLabel("Size (w,h): ", JLabel.RIGHT));
    panel1.add(sliderWidth);
    panel1.add(sliderHeight);
    panel1.add(new JLabel("Angles (Th0, Th): ", JLabel.RIGHT));
    panel1.add(sliderT0);
    panel1.add(sliderT);

    add(panel1, BorderLayout.NORTH);

    arcBox = new JComboBox(arcLabels);
    arcBox.setSelectedIndex(0);
    arcBox.setAlignmentX(Component.LEFT_ALIGNMENT);
    arcBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JComboBox cb = (JComboBox) e.getSource();
            canvas.arcType = arcTypes[cb.getSelectedIndex()];
            canvas.repaint();
        }
    });

    fillBox = new JComboBox(colorLabels);
    fillBox.setSelectedIndex(0);
    fillBox.setAlignmentX(Component.LEFT_ALIGNMENT);
    fillBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JComboBox cb = (JComboBox) e.getSource();
            canvas.fillColor = colors[cb.getSelectedIndex()];
            canvas.repaint();
        }
    });

    JPanel panel2 = new JPanel();
    panel2.setLayout(new GridLayout(1, 4));
    panel2.add(new JLabel("Arc Type: ", JLabel.RIGHT));
    panel2.add(arcBox);
    panel2.add(new JLabel("Fill Type: ", JLabel.RIGHT));
    panel2.add(fillBox);

    add(panel2, BorderLayout.SOUTH);
    add(canvas, BorderLayout.CENTER);
}

From source file:syg_package01.PanelRysunek2.java

private void initGUI() {
    try {/*from ww w  .  j  a v a  2  s  .  co m*/
        GridLayout thisLayout = new GridLayout(1, 1);
        thisLayout.setHgap(5);
        thisLayout.setVgap(5);
        thisLayout.setColumns(1);
        this.setLayout(thisLayout);
        setPreferredSize(new Dimension(400, 300));

        if (this.wykres) {
            double punkt = this.sygnalWyswietlany.gett1();
            HistogramDataset histogramDataset = new HistogramDataset();
            histogramDataset.setType(HistogramType.FREQUENCY);
            ArrayList<Double> punkty = new ArrayList<Double>();

            double ta = this.sygnalWyswietlany.gett1();

            if (this.sygnalWyswietlany.getrodzaj() == rodzaj_sygnalu.CIAGLY
                    || sygnalWyswietlany.getPunktyY().size() <= 0) {
                while (ta <= this.sygnalWyswietlany.gett1() + this.sygnalWyswietlany.getd()) {
                    punkt = this.sygnalWyswietlany.wykres_punkty(punkt, ta);
                    // this.sygnalWyswietlany.setPunktyY (punkt);
                    punkty.add(punkt);
                    ta = ta + this.sygnalWyswietlany.getkroczek();
                }
            } else if (this.sygnalWyswietlany.getrodzaj() == rodzaj_sygnalu.DYSKRETNY) {
                int iloscProbek = (int) (this.sygnalWyswietlany.getT()
                        / (Double) this.sygnalWyswietlany.getkroczek());
                for (int i = 0; i < iloscProbek; i++) {
                    punkt = this.sygnalWyswietlany.getPunktzindexu(i);
                    punkty.add(punkt);
                    ta = ta + this.sygnalWyswietlany.getkroczek();
                }
            }

            JFreeChart chartHist;
            if (this.iloscPrzedzialowHistogramu > 0) {
                double[] tablicaHistogramu = new double[punkty.size()];
                for (int licznik = 0; licznik < punkty.size(); ++licznik)
                    tablicaHistogramu[licznik] = punkty.get(licznik);

                histogramDataset.addSeries("Histogram (" + iloscPrzedzialowHistogramu + ")", tablicaHistogramu,
                        this.iloscPrzedzialowHistogramu);

                chartHist = ChartFactory.createHistogram("Histogram", null, null, histogramDataset,
                        PlotOrientation.VERTICAL, true, false, false);

                final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
                renderer.setSeriesLinesVisible(0, false);

                ChartPanel chartpanel1 = new ChartPanel(chartHist);
                chartpanel1.setDomainZoomable(true);

                this.add(chartpanel1);
            }
        }
        Application.getInstance().getContext().getResourceMap(getClass()).injectComponents(this);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:lu.lippmann.cdb.ext.hydviga.ui.GapsOverviewPanel.java

/**
 * Constructor./*from   www . j  a v a  2 s.  c o  m*/
 */
public GapsOverviewPanel(final AbstractTabView atv, final StationsDataProvider gcp) {
    this.atv = atv;

    this.gcp = gcp;

    this.jxp = new JXPanel();
    this.jxp.setLayout(new GridLayout(2, 1));

    final JXPanel highPanel = new JXPanel();
    highPanel.setLayout(new BoxLayout(highPanel, BoxLayout.X_AXIS));
    this.jxp.add(highPanel);

    this.tablePanel = new JXPanel();
    this.tablePanel.setLayout(new BorderLayout());
    highPanel.add(this.tablePanel);

    this.geomapPanel = new JXPanel();
    this.geomapPanel.add(gcp.getMapPanel(new ArrayList<String>(), new ArrayList<String>(), false));
    highPanel.add(this.geomapPanel);

    this.visualOverviewPanel = new JXPanel();
    this.visualOverviewPanel.setLayout(new BorderLayout());
    this.jxp.add(this.visualOverviewPanel);
}

From source file:StringDistance.java

public StringDistance(String[] strs) throws InlineJavaException {
    frame = new JFrame("StringDistance");
    Container p = frame.getContentPane();
    p.setLayout(new GridLayout(0, 2));

    // The input fields, including labels:
    tf = new JTextField[2];
    for (int i = 0; i < 2; i++) {
        p.add(new JLabel("String " + i + ":"));
        tf[i] = new JTextField(20);
        if ((strs != null) && (i < strs.length))
            tf[i].setText(strs[i]);/*from   ww w  .java2s . c  om*/
        p.add(tf[i]);
    }

    // The output field, including label:
    p.add(new JLabel("Distance:"));
    dist = new JTextField(5);
    dist.setEditable(false);
    p.add(dist);

    // The main action button:
    go = new JButton("Compute distance");
    go.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            dist.setText(Integer.toString(match(tf[0].getText(), tf[1].getText())));
        }
    });
    p.add(go);

    // To finish off:
    exit = new JButton("Exit");
    exit.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            frame.dispose();
            System.exit(0);
        }
    });
    p.add(exit);

    if ((strs != null) && (strs.length > 1))
        dist.setText(Integer.toString(match(tf[0].getText(), tf[1].getText())));
    frame.pack();
}

From source file:syg_package01.PanelRysunek_Wykres.java

private void initGUI() {
    try {/*from  w w  w .ja  v  a2s .  c  o m*/
        GridLayout thisLayout = new GridLayout(1, 1);
        thisLayout.setHgap(5);
        thisLayout.setVgap(5);
        thisLayout.setColumns(1);
        this.setLayout(thisLayout);
        setPreferredSize(new Dimension(400, 300));

        if (this.wykres) {

            XYSeries series = new XYSeries("Wykres");
            double punkt;
            double ta = this.sygnalWyswietlany.gett1();

            if (this.sygnalWyswietlany.getrodzaj() == rodzaj_sygnalu.CIAGLY
                    || sygnalWyswietlany.getPunktyY().size() <= 0) {
                punkt = this.sygnalWyswietlany.gett1();
                while (ta <= this.sygnalWyswietlany.gett1() + this.sygnalWyswietlany.getd()) {
                    punkt = this.sygnalWyswietlany.wykres_punkty(punkt, ta);
                    this.sygnalWyswietlany.setPunktyY(punkt);
                    series.add(ta, punkt);
                    if (this.sygnalWyswietlany.gettyp() < 10)
                        ta = ta + this.sygnalWyswietlany.getkroczek();
                    else
                        ta = ta + this.sygnalWyswietlany.getkroczek() * 10;
                }
            } else if (this.sygnalWyswietlany.getrodzaj() == rodzaj_sygnalu.DYSKRETNY
                    && sygnalWyswietlany.getPunktyY().size() > 0) {
                punkt = sygnalWyswietlany.getPunktzindexu(0);
                int iloscProbek = (int) (this.sygnalWyswietlany.getPunktyY().size());
                for (int i = 1; i < iloscProbek; i++) {
                    punkt = this.sygnalWyswietlany.getPunktzindexu(i);
                    series.add(ta, punkt);
                    // if (this.sygnalWyswietlany.gettyp() < 10)
                    // ta = ta + this.sygnalWyswietlany.getkroczek();
                    // else
                    ta = ta + this.sygnalWyswietlany.getkroczek();
                }
            }

            XYSeriesCollection dataset = new XYSeriesCollection(series);
            JFreeChart chart;

            if ((this.sygnalWyswietlany.gettyp() < 10)
                    && (this.sygnalWyswietlany.getrodzaj() == rodzaj_sygnalu.CIAGLY)) {
                chart = ChartFactory.createXYLineChart(null, null, null, dataset, PlotOrientation.VERTICAL,
                        true, true, true);

                final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
                renderer.setSeriesLinesVisible(0, false);
            } else {
                chart = ChartFactory.createXYLineChart(null, null, null, dataset, PlotOrientation.VERTICAL,
                        true, true, true);

                final XYPlot plot = chart.getXYPlot();
                final XYDotRenderer renderer = new XYDotRenderer();
                renderer.setDotHeight(3);
                renderer.setDotWidth(3);
                plot.setRenderer(renderer);

                final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
                rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
            }

            ChartPanel chartpanel = new ChartPanel(chart);
            chartpanel.setDomainZoomable(true);

            this.add(chartpanel);
        }

        Application.getInstance().getContext().getResourceMap(getClass()).injectComponents(this);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:gtu.xml.xstream.iisi.MQDecodeUI.java

private void initGUI() {
    try {/*from  w  w w  . j  a v  a2 s.  co m*/
        JCommonUtil.defaultLookAndFeel();
        GridLayout thisLayout = new GridLayout(3, 1);
        thisLayout.setColumns(1);
        thisLayout.setHgap(5);
        thisLayout.setVgap(5);
        thisLayout.setRows(3);
        getContentPane().setLayout(thisLayout);
        setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        {
            beforeArea = new JTextArea();
            getContentPane().add(beforeArea);
        }
        {
            afterArea = new JTextArea();
            getContentPane().add(afterArea);
        }
        {
            jPanel1 = new JPanel();
            FlowLayout jPanel1Layout = new FlowLayout();
            getContentPane().add(jPanel1);
            jPanel1.setPreferredSize(new java.awt.Dimension(546, 38));
            jPanel1.setLayout(jPanel1Layout);
            {
                executeBtn = new JButton();
                jPanel1.add(executeBtn);
                executeBtn.setText("\u7522\u751f");
                executeBtn.setPreferredSize(new java.awt.Dimension(78, 22));
                executeBtn.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent evt) {
                        try {
                            Validate.notBlank(beforeArea.getText(), "messgaeContent");
                            String msg2 = beforeArea.getText();

                            XmlParserImpl xmlParserImpl = new XmlParserImpl();
                            final String jmsMessageXML = StringCompressUtil.uncompress(msg2);
                            JmsMessageNew jmsMessageNew = (JmsMessageNew) xmlParserImpl
                                    .parseToObj(jmsMessageXML);
                            String returnMessage = jmsMessageNew.getMessageXML();
                            System.out.println(returnMessage);
                            afterArea.setText(returnMessage);
                            System.out.println("done...");
                        } catch (Exception ex) {
                            JCommonUtil.handleException(ex);
                        }
                    }
                });
            }
            {
                cleanBtn = new JButton();
                jPanel1.add(cleanBtn);
                cleanBtn.setText("\u6e05\u9664");
                cleanBtn.setPreferredSize(new java.awt.Dimension(78, 22));
                cleanBtn.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent evt) {
                        try {
                            beforeArea.setText("");
                            afterArea.setText("");
                        } catch (Exception ex) {
                            JCommonUtil.handleException(ex);
                        }
                    }
                });
            }
        }
        pack();
        this.setSize(554, 402);
    } catch (Exception e) {
        //add your error handling code here
        e.printStackTrace();
    }
}

From source file:ColorMenu.java

public ColorMenu(String name) {
    super(name);//from   www.  j av a2  s .  c  o  m

    _unselectedBorder = new CompoundBorder(new MatteBorder(1, 1, 1, 1, getBackground()),
            new BevelBorder(BevelBorder.LOWERED, Color.WHITE, Color.GRAY));

    _selectedBorder = new CompoundBorder(new MatteBorder(2, 2, 2, 2, Color.RED),
            new MatteBorder(1, 1, 1, 1, getBackground()));

    _activeBorder = new CompoundBorder(new MatteBorder(2, 2, 2, 2, Color.BLUE),
            new MatteBorder(1, 1, 1, 1, getBackground()));

    JPanel p = new JPanel();
    p.setBorder(new EmptyBorder(5, 5, 5, 5));
    p.setLayout(new GridLayout(8, 8));
    _colorPanes = new HashMap();

    int values[] = new int[] { 0, 128, 192, 255 };

    for (int r = 0; r < values.length; r++)
        for (int g = 0; g < values.length; g++)
            for (int b = 0; b < values.length; b++) {
                Color color = new Color(values[r], values[g], values[b]);
                ColorPane colorPane = new ColorPane(color);
                p.add(colorPane);
                _colorPanes.put(color, colorPane);
            }

    add(p);

}

From source file:com.emental.mindraider.ui.dialogs.FtsJDialog.java

public FtsJDialog() {
    super(Messages.getString("FtsJDialog.title"));

    JPanel dialogPanel = new JPanel();
    dialogPanel.setBorder(new EmptyBorder(5, 10, 0, 10));
    dialogPanel.setLayout(new BorderLayout());

    JPanel contentAndButtons = new JPanel(new GridLayout(2, 1));
    JPanel contentPanel = new JPanel(new BorderLayout());

    // 1a./*  w ww  .  ja va2 s.c o m*/
    // TODO add help like in eclipse
    contentPanel.add(new JLabel(Messages.getString("FtsJDialog.searchString")), BorderLayout.NORTH);
    // 1b.
    String[] knownSearches = new String[] { "", "RDF", "mind", "concept", "China" };
    ftsCombo = new JComboBox(knownSearches);
    ftsCombo.setPreferredSize(new Dimension(200, 18));
    ftsCombo.setEditable(true);
    ftsCombo.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if ("comboBoxEdited".equals(e.getActionCommand())) {
                search();
            }
        }
    });
    contentPanel.add(ftsCombo, BorderLayout.SOUTH);
    contentAndButtons.add(contentPanel);

    // 2.
    JPanel p = new JPanel();
    p.setLayout(new FlowLayout(FlowLayout.CENTER, 1, 5));
    JButton searchButton = new JButton(Messages.getString("FtsJDialog.searchButton"));
    searchButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            search();
        }
    });
    p.add(searchButton);

    JButton cancelButton = new JButton(Messages.getString("FtsJDialog.cancel"));
    cancelButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            dispose();
        }
    });
    p.add(cancelButton);

    contentAndButtons.add(p);

    dialogPanel.add(contentAndButtons, BorderLayout.CENTER);

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

    // show
    pack();
    Gfx.centerAndShowWindow(this);
}

From source file:syg_package01.PanelRysunek.java

private void initGUI() {
    try {/*from   w  w w . j a  v a  2s.c o  m*/
        GridLayout thisLayout = new GridLayout(1, 1);
        thisLayout.setHgap(5);
        thisLayout.setVgap(5);
        thisLayout.setColumns(1);
        this.setLayout(thisLayout);
        setPreferredSize(new Dimension(400, 300));

        if (this.wykres) {
            double punkt = this.sygnalWyswietlany.gett1();
            double punktZapisu = this.sygnalWyswietlany.gett1();
            XYSeries series = new XYSeries("Wykres");

            double krok;
            int typ = this.sygnalWyswietlany.gettyp();
            double f = 1.0 / this.sygnalWyswietlany.getT();
            double t = this.sygnalWyswietlany.gett1();

            // if (this.sygnalWyswietlany.gettyp()==1){
            /*
             * for (double i = this.sygnalWyswietlany.gett1(); i <
             * this.sygnalWyswietlany.t1+this.sygnalWyswietlany.getts();
             * i++){ punkt= this.sygnalWyswietlany.wykres_punkty(punkt, i);
             * series.add(i, punkt)} ;
             */

            double ta = this.sygnalWyswietlany.gett1();

            if (this.sygnalWyswietlany.getrodzaj() == rodzaj_sygnalu.CIAGLY
                    || sygnalWyswietlany.getPunktyY().size() <= 0) {
                while (ta <= this.sygnalWyswietlany.gett1() + this.sygnalWyswietlany.getd()) {
                    // punkt=this.sygnalWyswietlany.sygnalS1();
                    punkt = this.sygnalWyswietlany.wykres_punkty(punkt, ta);
                    this.sygnalWyswietlany.setPunktyY(punkt);
                    // punkt=this.sygnalWyswietlany.sygnalS3(ta);
                    series.add(ta, punkt);
                    if (this.sygnalWyswietlany.gettyp() < 10)
                        ta = ta + this.sygnalWyswietlany.getkroczek();
                    else
                        ta = ta + this.sygnalWyswietlany.getkroczek() * 10;
                }
            } else if (this.sygnalWyswietlany.getrodzaj() == rodzaj_sygnalu.DYSKRETNY
                    && sygnalWyswietlany.getPunktyY().size() > 0) {
                int iloscProbek = (int) (this.sygnalWyswietlany.getPunktyY().size());
                for (int i = 0; i < iloscProbek; i++) {
                    // punkt=this.sygnalWyswietlany.sygnalS1();
                    punkt = this.sygnalWyswietlany.getPunktzindexu(i);
                    // punkt=this.sygnalWyswietlany.sygnalS3(ta);
                    series.add(ta, punkt);
                    if (this.sygnalWyswietlany.gettyp() < 10)
                        ta = ta + this.sygnalWyswietlany.getkroczek();
                    else
                        ta = ta + this.sygnalWyswietlany.getkroczek() * 10;
                }
            }

            // this.sygnalWyswietlany.ustawPunkty();
            /*
             * int liczba= this.sygnalWyswietlany.punktyY.size(); int
             * liczba2= 0;
             * 
             * while (liczba2<liczba) { ta= ta+
             * this.sygnalWyswietlany.getkroczek();
             * series.add(ta,this.sygnalWyswietlany
             * .getPunktzindexu(liczba2));
             * 
             * }
             */

            XYSeriesCollection dataset = new XYSeriesCollection(series);

            // JFreeChart chart = ChartFactory.createHistogram("Histogram",
            // "x", "y", dataset, PlotOrientation.VERTICAL, false, false,
            // false);

            JFreeChart chart;

            /*
             * JFreeChart chart = ChartFactory.createScatterPlot("Wykres",
             * "t[s]", "Warto", dataset, PlotOrientation.VERTICAL, false,
             * false, false);
             */
            if ((this.sygnalWyswietlany.gettyp() < 10)
                    || (this.sygnalWyswietlany.getrodzaj() == rodzaj_sygnalu.CIAGLY)) {
                chart = ChartFactory.createXYLineChart(null, null, null, dataset, PlotOrientation.VERTICAL,
                        true, true, true);

                final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
                renderer.setSeriesLinesVisible(0, false);
            } else {
                chart = ChartFactory.createXYLineChart(null, null, null, dataset, PlotOrientation.VERTICAL,
                        true, true, true);

                final XYPlot plot = chart.getXYPlot();
                // plot.setBackgroundPaint(Color.lightGray);
                // plot.setDomainGridlinePaint(Color.white);
                // plot.setRangeGridlinePaint(Color.white);

                // final XYLineAndShapeRenderer renderer = new
                // XYLineAndShapeRenderer();
                final XYDotRenderer renderer = new XYDotRenderer();
                renderer.setDotHeight(3);
                renderer.setDotWidth(3);
                plot.setRenderer(renderer);

                final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
                rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
            }

            // ChartPanel chartpanel = new ChartPanel(wykres2);
            ChartPanel chartpanel = new ChartPanel(chart);
            chartpanel.setDomainZoomable(true);

            this.add(chartpanel);
        }

        Application.getInstance().getContext().getResourceMap(getClass()).injectComponents(this);
    } catch (Exception e) {
        e.printStackTrace();
    }
}