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:statistic.ca.gui.DiagramContainer.java

public void remove(String diagramName) {
    if (contains(diagramName)) {
        JPanel p = getTupel(diagramName);
        if (p != null) {
            diagramList.remove(p);// w  w w. j  a v  a 2 s  . co m
            diagramMapping.clear();
            for (DiagramTupel dt : diagramList) {
                diagramMapping.put(dt.getTitle(), diagramList.indexOf(dt));
            }

            super.removeAll();

            setLayout(new GridLayout((int) (Math.ceil((double) diagramList.size() / 2)), 2));

            for (DiagramTupel dt : diagramList) {
                add(dt.getDiagram());
                (dt.getDiagram()).addMouseListener(parent.new diagramClick());
            }

            repaint();
            validate();
        }
    }
}

From source file:FocusConceptsDemo.java

public FocusConceptsDemo() {
    super(new BorderLayout());

    b1 = new JButton("JButton");
    b2 = new JButton("JButton");
    b3 = new JButton("JButton");
    b4 = new JButton("JButton");
    JPanel buttonPanel = new JPanel(new GridLayout(1, 1));
    buttonPanel.add(b1);/* ww  w  .  ja va  2s .  c o m*/
    buttonPanel.add(b2);
    buttonPanel.add(b3);
    buttonPanel.add(b4);

    text1 = new JTextArea("JTextArea", 15, 40);
    JPanel textAreaPanel = new JPanel(new BorderLayout());
    textAreaPanel.add(text1, BorderLayout.CENTER);

    t1 = new JTextField("JTextField");
    t2 = new JTextField("JTextField");
    t3 = new JTextField("JTextField");
    t4 = new JTextField("JTextField");
    JPanel textFieldPanel = new JPanel(new GridLayout(1, 1));
    textFieldPanel.add(t1);
    textFieldPanel.add(t2);
    textFieldPanel.add(t3);
    textFieldPanel.add(t4);

    add(buttonPanel, BorderLayout.PAGE_START);
    add(textAreaPanel, BorderLayout.CENTER);
    add(textFieldPanel, BorderLayout.PAGE_END);
    setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
}

From source file:components.SimpleTableSelectionDemo.java

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

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

    final Object[][] data = { { "Kathy", "Smith", "Snowboarding", new Integer(5), new Boolean(false) },
            { "John", "Doe", "Rowing", new Integer(3), new Boolean(true) },
            { "Sue", "Black", "Knitting", new Integer(2), new Boolean(false) },
            { "Jane", "White", "Speed reading", new Integer(20), new Boolean(true) },
            { "Joe", "Brown", "Pool", new Integer(10), new Boolean(false) } };

    final JTable table = new JTable(data, columnNames);
    table.setPreferredScrollableViewportSize(new Dimension(500, 70));
    table.setFillsViewportHeight(true);/*from ww  w .j  a  v a 2  s  .c  om*/

    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.");
                }
            }
        });
    } 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:SynthApplication.java

public Component createComponents() {
    JButton button = new JButton("I'm a Swing button!");
    button.setMnemonic(KeyEvent.VK_I);
    button.addActionListener(this);
    label.setLabelFor(button);/*from  w  ww. ja  va  2 s. c om*/

    /*
     * An easy way to put space between a top-level container
     * and its contents is to put the contents in a JPanel
     * that has an "empty" border.
     */
    JPanel pane = new JPanel(new GridLayout(0, 1));
    pane.add(button);
    pane.add(label);
    pane.setBorder(BorderFactory.createEmptyBorder(30, //top
            30, //left
            10, //bottom
            30) //right
    );

    return pane;
}

From source file:misc.TrackFocusDemo.java

public TrackFocusDemo() {
    super(new BorderLayout());

    JPanel mugshots = new JPanel(new GridLayout(2, 3));
    pic1 = new Picture(createImageIcon("images/" + mayaString + ".jpg", mayaString).getImage());
    pic1.setName("1");
    mugshots.add(pic1);/*from  w  w w  .j  a  va  2s .  co  m*/
    pic2 = new Picture(createImageIcon("images/" + anyaString + ".jpg", anyaString).getImage());
    pic2.setName("2");
    mugshots.add(pic2);
    pic3 = new Picture(createImageIcon("images/" + laineString + ".jpg", laineString).getImage());
    pic3.setName("3");
    mugshots.add(pic3);
    pic4 = new Picture(createImageIcon("images/" + cosmoString + ".jpg", cosmoString).getImage());
    pic4.setName("4");
    mugshots.add(pic4);
    pic5 = new Picture(createImageIcon("images/" + adeleString + ".jpg", adeleString).getImage());
    pic5.setName("5");
    mugshots.add(pic5);
    pic6 = new Picture(createImageIcon("images/" + alexiString + ".jpg", alexiString).getImage());
    pic6.setName("6");
    mugshots.add(pic6);

    info = new JLabel("Nothing selected");

    setPreferredSize(new Dimension(450, 350));
    add(mugshots, BorderLayout.CENTER);
    add(info, BorderLayout.PAGE_END);
    setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));

    KeyboardFocusManager focusManager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
    focusManager.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent e) {
            String prop = e.getPropertyName();
            if (("focusOwner".equals(prop)) && ((e.getNewValue()) instanceof Picture)) {

                Component comp = (Component) e.getNewValue();
                String name = comp.getName();
                Integer num = new Integer(name);
                int index = num.intValue();
                if (index < 0 || index > comments.length) {
                    index = 0;
                }
                info.setText(comments[index]);
            }
        }
    });
}

From source file:components.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  w w . j  a va2s.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));
    table.setFillsViewportHeight(true);

    //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:jotp.java

public void init() {

    setBackground(Color.white);// w w w  .  ja v a 2 s  .  c  o m
    setLayout(new GridLayout(6, 1));

    Panel panel1 = new Panel();
    add(panel1);
    Font titlefont = new Font("TimesRoman", Font.BOLD, 14);
    panel1.setFont(titlefont);
    panel1.add(new Label(String.valueOf(version) + ": The Java OTP (aka S/Key) calculator!"));
    Panel panel2 = new Panel();
    panel2.setLayout(new FlowLayout());
    add(panel2);
    panel2.add(new Label("Challenge (e.g. \"55 latour1\"):"));
    chaltf = new TextField(24);
    panel2.add(chaltf);

    Panel panel3 = new Panel();
    panel3.setLayout(new FlowLayout());
    add(panel3);
    panel3.add(new Label("Secret Password:"));
    pwtf = new TextField(24);
    pwtf.setEchoCharacter('*');
    panel3.add(pwtf);

    Panel panel4 = new Panel();
    panel4.setLayout(new FlowLayout());
    add(panel4);

    panel4.add(new Button(String.valueOf(md4label)));
    panel4.add(new Button(String.valueOf(md5label)));

    Panel panel6 = new Panel();
    panel6.setLayout(new FlowLayout());
    add(panel6);
    panel6.add(new Label("One-Time Password:", Label.LEFT));
    otptf = new TextField(40);
    panel6.add(otptf);

    Panel panel7 = new Panel();
    add(panel7);
    panel7.add(new Label("jotp by Harry Mantakos, " + "http://www.cs.umd.edu/~harry/jotp"));
}

From source file:ColorChooserMenu.java

public ColorMenu(String name) {
    super(name);/*from w ww. j a  v a 2s  .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(1, 1, 1, 1, Color.red),
            new MatteBorder(1, 1, 1, 1, getBackground()));
    activeBorder = new CompoundBorder(new MatteBorder(1, 1, 1, 1, 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));
    paneTable = new Hashtable();

    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 c = new Color(values[r], values[g], values[b]);
                ColorPane pn = new ColorPane(c);
                p.add(pn);
                paneTable.put(c, pn);
            }
        }
    }
    add(p);
}

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  va2s  . c  o  m*/

    // 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:gtu._work.ui.LogAppendStartEndUI.java

private void initGUI() {
    try {// w  w w .  j  a  v  a 2 s.  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();
                GridLayout jPanel1Layout = new GridLayout(10, 1);
                jPanel1.setLayout(jPanel1Layout);
                jTabbedPane1.addTab("jPanel1", null, jPanel1, null);
                {
                    jLabel1 = new JLabel();
                    jPanel1.add(jLabel1);
                    jLabel1.setText("java\u6a94");
                }
                {
                    javaSrcFileText = new JTextField();
                    jPanel1.add(javaSrcFileText);
                    JCommonUtil.jTextFieldSetFilePathMouseEvent(javaSrcFileText, false);
                }
                {
                    jLabel2 = new JLabel();
                    jPanel1.add(jLabel2);
                    jLabel2.setText("method\u958b\u59cb");
                }
                {
                    methodStartText = new JTextField();
                    methodStartText.setText("\"#. ${method} .s\"");
                    jPanel1.add(methodStartText);
                }
                {
                    jLabel3 = new JLabel();
                    jPanel1.add(jLabel3);
                    jLabel3.setText("method\u7d50\u675f");
                }
                {
                    methodEndText = new JTextField();
                    methodEndText.setText("\"#. ${method} .e\"");
                    jPanel1.add(methodEndText);
                }
                {
                    jLabel4 = new JLabel();
                    jPanel1.add(jLabel4);
                    jLabel4.setText(
                            "\u7528\u684c\u9762\u8a2d\u5b9a\u6a94\u6c7a\u5b9adebug\u958b\u8d77\u6216\u95dc\u9589");
                }
                {
                    ComboBoxModel onOffDebugSwitchComboBoxModel = new DefaultComboBoxModel(
                            new String[] { "false", "true" });
                    onOffDebugSwitchComboBox = new JComboBox();
                    jPanel1.add(onOffDebugSwitchComboBox);
                    onOffDebugSwitchComboBox.setModel(onOffDebugSwitchComboBoxModel);
                }
                {
                    executeBtn = new JButton();
                    jPanel1.add(executeBtn);
                    executeBtn.setText("\u57f7\u884c");
                    executeBtn.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            executeBtnActionPerformed(evt);
                        }
                    });
                }
            }
        }
        pack();
        this.setSize(587, 404);
    } catch (Exception e) {
        //add your error handling code here
        e.printStackTrace();
    }
}