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:org.rioproject.examples.hospital.ui.PatientStatsPanel.java

public PatientStatsPanel() {
    super(new BorderLayout(8, 8));
    setBorder(BorderFactory.createEmptyBorder(2, 8, 8, 8));
    patientLabel = new JLabel(getLabelText(null));
    add(patientLabel, BorderLayout.NORTH);
    pulseTimeSeries.setMaximumItemAge(5 * MINUTE);
    temperatureTimeSeries.setMaximumItemAge(5 * MINUTE);
    TimeSeriesCollection pulseDataSet = new TimeSeriesCollection(pulseTimeSeries);
    TimeSeriesCollection temperatureDataSet = new TimeSeriesCollection(temperatureTimeSeries);
    JFreeChart pulseChart = createTimeSeriesChart(pulseDataSet, Color.RED);
    JFreeChart temperatureChart = createTimeSeriesChart(temperatureDataSet, Color.BLUE);

    JPanel chartPanel = new JPanel(new GridLayout(1, 2));
    chartPanel.add(makeChartPanel(pulseChart));
    chartPanel.add(makeChartPanel(temperatureChart));
    add(chartPanel, BorderLayout.CENTER);
    scheduler = Executors.newSingleThreadScheduledExecutor();
    scheduler.scheduleAtFixedRate(new FeederTask(), 0, 2, TimeUnit.SECONDS);
}

From source file:SimpleTableSelectionDemo.java

public SimpleTableSelectionDemo() {
    super(new GridLayout(1, 0));

    final String[] columnNames = { "First Name", "Last Name", "Sport", "# of Years", "Vegetarian" };

    final Object[][] data = { { "Mary", "Campione", "Snowboarding", new Integer(5), new Boolean(false) },
            { "Alison", "Huml", "Rowing", new Integer(3), new Boolean(true) },
            { "Kathy", "Walrath", "Knitting", new Integer(2), new Boolean(false) },
            { "Sharon", "Zakhour", "Speed reading", new Integer(20), new Boolean(true) },
            { "Philip", "Milne", "Pool", new Integer(10), new Boolean(false) } };

    final JTable table = new JTable(data, columnNames);
    table.setPreferredScrollableViewportSize(new Dimension(500, 70));

    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    if (ALLOW_ROW_SELECTION) { // true by default
        ListSelectionModel rowSM = table.getSelectionModel();
        rowSM.addListSelectionListener(new ListSelectionListener() {
            public void valueChanged(ListSelectionEvent e) {
                //Ignore extra messages.
                if (e.getValueIsAdjusting())
                    return;

                ListSelectionModel lsm = (ListSelectionModel) e.getSource();
                if (lsm.isSelectionEmpty()) {
                    System.out.println("No rows are selected.");
                } else {
                    int selectedRow = lsm.getMinSelectionIndex();
                    System.out.println("Row " + selectedRow + " is now selected.");
                }//from  w  ww.j  a  va 2 s  .com
            }
        });
    } else {
        table.setRowSelectionAllowed(false);
    }

    if (ALLOW_COLUMN_SELECTION) { // false by default
        if (ALLOW_ROW_SELECTION) {
            //We allow both row and column selection, which
            //implies that we *really* want to allow individual
            //cell selection.
            table.setCellSelectionEnabled(true);
        }
        table.setColumnSelectionAllowed(true);
        ListSelectionModel colSM = table.getColumnModel().getSelectionModel();
        colSM.addListSelectionListener(new ListSelectionListener() {
            public void valueChanged(ListSelectionEvent e) {
                //Ignore extra messages.
                if (e.getValueIsAdjusting())
                    return;

                ListSelectionModel lsm = (ListSelectionModel) e.getSource();
                if (lsm.isSelectionEmpty()) {
                    System.out.println("No columns are selected.");
                } else {
                    int selectedCol = lsm.getMinSelectionIndex();
                    System.out.println("Column " + selectedCol + " is now selected.");
                }
            }
        });
    }

    if (DEBUG) {
        table.addMouseListener(new MouseAdapter() {
            public void mouseClicked(MouseEvent e) {
                printDebugData(table);
            }
        });
    }

    //Create the scroll pane and add the table to it.
    JScrollPane scrollPane = new JScrollPane(table);

    //Add the scroll pane to this panel.
    add(scrollPane);
}

From source file:Main.java

public Main() {
    formTextFieldFormat = NumberFormat.getNumberInstance();
    formTextFieldFormat.setMinimumFractionDigits(2);
    formTextFieldFormat.setMaximumFractionDigits(2);
    formTextFieldFormat.setRoundingMode(RoundingMode.HALF_UP);

    focusLabel.setPreferredSize(new Dimension(120, 27));
    formTextField = new JFormattedTextField(formTextFieldFormat);
    formTextField.setValue(amount);/*w  ww  .  j  a va  2  s. co m*/
    formTextField.setPreferredSize(new Dimension(120, 27));
    formTextField.setHorizontalAlignment(SwingConstants.RIGHT);
    formTextField.addFocusListener(new FocusListener() {

        @Override
        public void focusGained(FocusEvent e) {
            formTextField.requestFocus();
            formTextField.setText(formTextField.getText());
            formTextField.selectAll();
        }

        @Override
        public void focusLost(FocusEvent e) {
            double t1a1 = (((Number) formTextField.getValue()).doubleValue());
            if (t1a1 < 1000) {
                formTextField.setValue(amount);
            }
        }
    });

    docLabel.setPreferredSize(new Dimension(120, 27));

    formTextField1 = new JFormattedTextField(formTextFieldFormat);
    formTextField1.setValue(amount);

    formTextField1.setHorizontalAlignment(SwingConstants.RIGHT);
    formTextField1.addFocusListener(new FocusListener() {

        @Override
        public void focusGained(FocusEvent e) {
            formTextField1.requestFocus();
            formTextField1.setText(formTextField1.getText());
            formTextField1.selectAll();
        }

        @Override
        public void focusLost(FocusEvent e) {
        }
    });
    formTextField1.getDocument().addDocumentListener(docListener);

    pnl = new JPanel();
    pnl.setBorder(new EmptyBorder(2, 2, 2, 2));
    pnl.setLayout(new GridLayout(2, 2));
    pnl.add(focusLabel);
    pnl.add(formTextField);
    pnl.add(docLabel);
    pnl.add(formTextField1);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(pnl, BorderLayout.CENTER);
    frame.setLocation(200, 200);
    frame.pack();
    frame.setVisible(true);
    formTextFieldFocus1();
}

From source file:MainWindow.java

public MainWindow() {
    // Login Routine
    loginDialog = new LoginDialog();
    // loginDialog.nameField.setText("cornelius.preidel@googlemail.com");
    // loginDialog.passwordField.setText("germany");
    loginDialog.setSize(400, 150);/*from  w  ww  .  ja  v  a  2s  .c o  m*/
    loginDialog.setModal(true);
    loginDialog.setLocationRelativeTo(null);
    loginDialog.setVisible(true);

    // Get the connected ApiCore
    core = loginDialog._core;

    // Init the UI
    mainFrame = new JFrame("MainApplication");
    mainFrame.setSize(500, 500);
    mainFrame.setLocationRelativeTo(null);
    mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    mainFrame.setLayout(new GridLayout(5, 1));

    // WebProjectsList webprojectlist = new WebProjectsList(core);
    // mainFrame.add(webprojectlist);

    // Create the APIS
    Teams teamsAPI = new Teams(core);
    final Projects projectsAPI = new Projects(core);
    final Divisions divisionsAPI = new Divisions(core);
    final Attachments attachmentAPI = new Attachments(core);
    final Issues issueAPI = new Issues(core);

    // TEAMS List
    TeamsList teamList = new TeamsList();
    teamList.setTeams(teamsAPI.GetTeams());
    mainFrame.add(teamList);

    // PROJECTS  List
    projectsList = new ProjectsList();
    mainFrame.add(projectsList);

    // DIVISIONS List
    divisionsList = new DivisionsList();
    // mainFrame.add(divisionsList);

    // DIVISIONS Table
    divisionsTable = new DivisionsTable(core);
    mainFrame.add(divisionsTable);

    // Attachments
    attachmentsList = new AttachmentsList();
    mainFrame.add(attachmentsList);

    // Attachments
    issuesList = new IssuesList();
    mainFrame.add(issuesList);

    PropertyChangeListener propertyChangeListener = new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent propertyChangeEvent) {
            String property = propertyChangeEvent.getPropertyName();
            if ("selectedTeam".equals(property)) {
                DtoTeam selectedTeam = (DtoTeam) propertyChangeEvent.getNewValue();

                // Set the global slug
                core.currentTeam = selectedTeam;
                projectsList.setProjects(projectsAPI.GetProjects());
            } else if ("selectedProject".equals(property)) {
                DtoProject selectedProject = (DtoProject) propertyChangeEvent.getNewValue();
                // Divisions
                divisionsList.setDivisions(divisionsAPI.GetDivisions(selectedProject.GetId()));
                divisionsTable.setDivisions(divisionsAPI.GetDivisions(selectedProject.GetId()));
                // Attachments
                attachmentsList.setAttachments(attachmentAPI.GetAttachments(selectedProject.GetId()));
                // Issues
                issuesList.setIssues(issueAPI.GetIssues(selectedProject.GetId()));
            } else if ("selectedDivision".equals(property)) {
                DtoDivision selectedDivision = (DtoDivision) propertyChangeEvent.getNewValue();
                // What to do with the division?
            } else if ("selectedIssue".equals(property)) {
                DtoIssue selectedDivision = (DtoIssue) propertyChangeEvent.getNewValue();
                // What to do with the division?
            } else {
                if ("selectedAttachment".equals(property)) {
                    DtoAttachment selectedAttachment = (DtoAttachment) propertyChangeEvent.getNewValue();
                    InputStream stream = attachmentAPI.DownloadAttachment(selectedAttachment.GetId());

                    try {
                        byte[] bytes = IOUtils.toByteArray(stream);
                        JFileChooser chooser = new JFileChooser();
                        int returnVal = chooser.showSaveDialog(chooser);
                        File file = chooser.getSelectedFile();

                        FileOutputStream fos = new FileOutputStream(file);
                        fos.write(bytes);
                        fos.flush();
                        fos.close();
                    } catch (IOException e) {
                        LOG.error(e.getMessage(), e);
                    }
                }
            }
        }
    };

    // Add Listener
    teamList.addPropertyChangeListener(propertyChangeListener);
    projectsList.addPropertyChangeListener(propertyChangeListener);
    divisionsList.addPropertyChangeListener(propertyChangeListener);
    divisionsTable.addPropertyChangeListener(propertyChangeListener);
    attachmentsList.addPropertyChangeListener(propertyChangeListener);
    issuesList.addPropertyChangeListener(propertyChangeListener);
}

From source file:TableToolTipsDemo.java

public TableToolTipsDemo() {
    super(new GridLayout(1, 0));

    JTable table = new JTable(new MyTableModel()) {

        //Implement table cell tool tips.
        public String getToolTipText(MouseEvent e) {
            String tip = null;//w ww.j a  v a 2 s . c  om
            java.awt.Point p = e.getPoint();
            int rowIndex = rowAtPoint(p);
            int colIndex = columnAtPoint(p);
            int realColumnIndex = convertColumnIndexToModel(colIndex);

            if (realColumnIndex == 2) { //Sport column
                tip = "This person's favorite sport to " + "participate in is: "
                        + getValueAt(rowIndex, colIndex);
            } else if (realColumnIndex == 4) { //Veggie column
                TableModel model = getModel();
                String firstName = (String) model.getValueAt(rowIndex, 0);
                String lastName = (String) model.getValueAt(rowIndex, 1);
                Boolean veggie = (Boolean) model.getValueAt(rowIndex, 4);
                if (Boolean.TRUE.equals(veggie)) {
                    tip = firstName + " " + lastName + " is a vegetarian";
                } else {
                    tip = firstName + " " + lastName + " is not a vegetarian";
                }
            } else {
                //You can omit this part if you know you don't
                //have any renderers that supply their own tool
                //tips.
                tip = super.getToolTipText(e);
            }
            return tip;
        }

        //Implement table header tool tips.
        protected JTableHeader createDefaultTableHeader() {
            return new JTableHeader(columnModel) {
                public String getToolTipText(MouseEvent e) {
                    String tip = null;
                    java.awt.Point p = e.getPoint();
                    int index = columnModel.getColumnIndexAtX(p.x);
                    int realIndex = columnModel.getColumn(index).getModelIndex();
                    return columnToolTips[realIndex];
                }
            };
        }
    };

    table.setPreferredScrollableViewportSize(new Dimension(500, 70));

    //Create the scroll pane and add the table to it.
    JScrollPane scrollPane = new JScrollPane(table);

    //Add the scroll pane to this panel.
    add(scrollPane);
}

From source file:TicTacToe.java

public void init() {
    JPanel p = new JPanel();
    p.setLayout(new GridLayout(2, 2));
    p.add(new JLabel("Rows", JLabel.CENTER));
    p.add(rows);/*from w  ww  . ja  va  2s  . com*/
    p.add(new JLabel("Columns", JLabel.CENTER));
    p.add(cols);
    Container cp = getContentPane();
    cp.add(p, BorderLayout.NORTH);
    JButton b = new JButton("go");
    b.addActionListener(new BL());
    cp.add(b, BorderLayout.SOUTH);
}

From source file:org.spantus.exp.segment.exec.DrawSegmentAnalysis.java

protected JFrame getFrame() {
    if (frame == null) {
        frame = new JFrame("Analysis result");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        JPanel panel = new JPanel();
        panel.setLayout(new GridLayout(0, 2));
        frame.setContentPane(panel);/*ww w. j  a  v  a  2 s. com*/
    }
    return frame;
}

From source file:de.burrotinto.jKabel.dispalyAS.DisplayK.java

@Bean(name = "bearbeitenPanel")
public JPanel getBearbeitenPanel(KabelTypAuswahlAAS kabelTypAuswahlAAS, TrommelAuswahlAAS tommelAAs,
        StreckenAAS streckenAAS, Color background) {

    kabelTypAuswahlAAS.addKabelTypListner(tommelAAs);
    kabelTypAuswahlAAS.addKabelTypListner(streckenAAS);

    tommelAAs.addTrommelListner(streckenAAS);

    JPanel l = new JPanel(new GridLayout(1, 2));
    JPanel all = new JPanel(new GridLayout(1, 2));

    JScrollPane kSP = new JScrollPane(kabelTypAuswahlAAS);
    l.add(kSP);//from w  ww.j a  va 2  s .c om
    l.add(new JScrollPane(tommelAAs));
    all.add(l);
    JScrollPane sc = new JScrollPane(streckenAAS);
    sc.setPreferredSize(new Dimension(740, 740));
    all.add(sc);

    kSP.setOpaque(false);
    sc.setOpaque(false);

    l.setBackground(background);
    kabelTypAuswahlAAS.setBackground(background);
    tommelAAs.setBackground(background);
    streckenAAS.setBackground(background);

    try {
        streckenAAS.setLogo(ImageIO.read(new File(ConfigReader.getInstance().getPath() + "logo.jpg")));
    } catch (IOException e) {
        streckenAAS.setLogo(null);
    }
    all.setBackground(background);
    return all;
}

From source file:com.joey.software.Launcher.microneedleAnalysis.DataAnalysisViewer.java

public void createJPanel() {
    setLayout(new BorderLayout());

    JPanel pan = new JPanel(new GridLayout(4, 1));
    pan.add(SwingToolkit.getLabel(modeBox, "Mode : ", 100));
    pan.add(SwingToolkit.getLabel(expFilter, "Exp : ", 100));
    pan.add(SwingToolkit.getLabel(viewFilter, "View : ", 100));
    pan.add(debugButton);/*from www .j a va 2 s  .com*/

    JPanel showPanel = new JPanel(new GridLayout(1, 3));
    showPanel.add(useSkin);
    showPanel.add(usePore);
    showPanel.add(usePoreSkin);
    showPanel.add(useTotal);

    JPanel temp = new JPanel(new BorderLayout());
    temp.add(pan, BorderLayout.CENTER);
    temp.add(showPanel, BorderLayout.SOUTH);

    add(temp, BorderLayout.NORTH);
    add(chartHolder, BorderLayout.CENTER);
    add(replot, BorderLayout.SOUTH);

    debugButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            saveDataAsCSV();
        }
    });
    ActionListener action = new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            replotData();
        }
    };

    useSkin.addActionListener(action);
    usePore.addActionListener(action);
    usePoreSkin.addActionListener(action);
    useTotal.addActionListener(action);
    modeBox.addActionListener(action);

    expFilter.getDocument().addDocumentListener(new DocumentListener() {

        @Override
        public void changedUpdate(DocumentEvent e) {
            replotData();
        }

        @Override
        public void insertUpdate(DocumentEvent e) {
            replotData();
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
            replotData();
        }
    });

    viewFilter.getDocument().addDocumentListener(new DocumentListener() {

        @Override
        public void changedUpdate(DocumentEvent e) {
            replotData();
        }

        @Override
        public void insertUpdate(DocumentEvent e) {
            replotData();
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
            replotData();
        }
    });

    replot.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            replotData();

        }
    });
}

From source file:com.anji.floatingeye.FloatingEyeDisplay.java

private void init(Java2DSurface surface, FloatingEye anEye) {
    eye = anEye;//from w  w w  .  j  a  v  a  2  s .c o m

    // this frame has 3 sections - status, surface canvas, and eye canvas
    addWindowListener(new WindowAdapter() {

        public void windowClosing(WindowEvent e) {
            setVisible(false);
            dispose();
        }
    });
    GridLayout mainLayout = new GridLayout(2, 1);
    mainLayout.setHgap(10);
    mainLayout.setVgap(10);
    getContentPane().setLayout(mainLayout);
    GridLayout topPanelLayout = new GridLayout(2, 1);
    topPanelLayout.setHgap(10);
    topPanelLayout.setVgap(10);
    Panel topPanel = new Panel(topPanelLayout);
    GridLayout bottomPanelLayout = new GridLayout(1, 2);
    bottomPanelLayout.setHgap(10);
    bottomPanelLayout.setVgap(10);
    Panel bottomPanel = new Panel(bottomPanelLayout);

    // 1 - status area
    statusArea = new TextArea("", 1, 1, TextArea.SCROLLBARS_VERTICAL_ONLY);
    statusArea.setEditable(false);
    statusArea.setFont(new Font("Dialog", Font.PLAIN, 10));
    statusArea.setSize(new Dimension(IMG_WIDTH * 2, IMG_HEIGHT / 2));

    // 2 - affinity history chart
    XYSeriesCollection seriesCollection = new XYSeriesCollection(affinitySeries);
    JFreeChart chart = ChartFactory.createXYLineChart("affinity history", "step", "affinity", seriesCollection,
            PlotOrientation.VERTICAL, false, false, false);
    ValueAxis rangeAxis = chart.getXYPlot().getRangeAxis();
    rangeAxis.setAutoRange(false);
    rangeAxis.setRange(0d, 1d);
    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new Dimension(IMG_WIDTH * 2, IMG_HEIGHT / 2));

    // 3 - surface canvas
    surfaceCanvas = new SurfaceCanvas(surface, eye, IMG_WIDTH, IMG_HEIGHT);
    surfaceCanvas.setBackground(Color.WHITE);

    // 4 - eye canvas
    eyeCanvas = new EyeCanvas(eye, IMG_WIDTH, IMG_HEIGHT);
    eyeCanvas.setBackground(Color.WHITE);

    topPanel.add(statusArea);
    topPanel.add(chartPanel);
    bottomPanel.add(surfaceCanvas);
    bottomPanel.add(eyeCanvas);
    getContentPane().add(topPanel);
    getContentPane().add(bottomPanel);

    pack();
}