Example usage for javax.swing JPanel setPreferredSize

List of usage examples for javax.swing JPanel setPreferredSize

Introduction

In this page you can find the example usage for javax.swing JPanel setPreferredSize.

Prototype

@BeanProperty(preferred = true, description = "The preferred size of the component.")
public void setPreferredSize(Dimension preferredSize) 

Source Link

Document

Sets the preferred size of this component.

Usage

From source file:fuel.gui.stats.StationStatsPanel.java

private void refreshGraphs() {
    graphContainer.removeAll();/* ww  w  . j  a  v  a  2 s .co  m*/
    DefaultPieDataset usageDataset = new DefaultPieDataset();
    try {
        for (Station station : database.getStations()) {
            ResultSet thisStation = database
                    .Query("SELECT SUM(liter) FROM fuelrecords WHERE stationId = " + station.getId(), true);
            thisStation.next();
            usageDataset.setValue(station.toString(), thisStation.getInt("1"));
        }

    } catch (SQLException ex) {
        JOptionPane.showMessageDialog(null, ex.getMessage() + ex.getCause());
    }
    JFreeChart usagePieChart = ChartFactory.createPieChart3D("", usageDataset, true, true, false);
    PiePlot3D plot3 = (PiePlot3D) usagePieChart.getPlot();
    plot3.setForegroundAlpha(0.6f);
    //plot3.setCircular(true);

    JPanel usagePieChartPanel = new ChartPanel(usagePieChart);
    usagePieChartPanel.setBorder(
            BorderFactory.createTitledBorder(BorderFactory.createTitledBorder("Tankstation verhouding")));
    usagePieChartPanel.setPreferredSize(new java.awt.Dimension(320, 240));

    DefaultPieDataset fuelDataset = new DefaultPieDataset();
    try {
        ResultSet numberResults = database.Query("SELECT DISTINCT typeOfGas FROM fuelrecords", true);
        while (numberResults.next()) {
            ResultSet thisStation = database.Query("SELECT SUM(liter) FROM fuelrecords WHERE typeOfGas = '"
                    + numberResults.getString("typeOfGas") + "'", true);
            thisStation.next();
            fuelDataset.setValue(numberResults.getString("typeOfGas"), thisStation.getInt("1"));
        }

    } catch (SQLException ex) {
        JOptionPane.showMessageDialog(null, ex.getMessage() + ex.getCause());
    }
    JFreeChart fuelPieChart = ChartFactory.createPieChart3D("", fuelDataset, true, true, false);
    PiePlot3D plot2 = (PiePlot3D) fuelPieChart.getPlot();
    plot2.setForegroundAlpha(0.6f);
    //plot3.setCircular(true);

    JPanel fuelPieChartPanel = new ChartPanel(fuelPieChart);
    fuelPieChartPanel.setBorder(
            BorderFactory.createTitledBorder(BorderFactory.createTitledBorder("Brandstof verhouding")));
    fuelPieChartPanel.setPreferredSize(new java.awt.Dimension(320, 240));

    DefaultCategoryDataset barDataset = new DefaultCategoryDataset();
    try {
        ResultSet motorThing = database.Query("SELECT cost/liter,date FROM fuelrecords ORDER BY date ASC",
                true);
        while (motorThing.next()) {
            barDataset.addValue(motorThing.getDouble("1"), motorThing.getString("date"), "Prijs per liter");
        }

    } catch (SQLException ex) {
        JOptionPane.showMessageDialog(null, ex.getMessage() + ex.getCause());
    }

    JFreeChart barChart = ChartFactory.createBarChart3D("", // chart title
            "", // domain axis label
            "Aantal", // range axis label
            barDataset, // data
            PlotOrientation.VERTICAL, false, // include legend
            true, // tooltips?
            false // URLs?
    );
    CategoryPlot plot = barChart.getCategoryPlot();
    BarRenderer3D renderer = (BarRenderer3D) plot.getRenderer();
    renderer.setDrawBarOutline(false);

    ChartPanel barChartPanel = new ChartPanel(barChart);
    barChartPanel.getChartRenderingInfo().setEntityCollection(null);
    barChartPanel.setBorder(BorderFactory.createTitledBorder("Prijs per liter"));
    barChartPanel.setPreferredSize(new java.awt.Dimension(320, 240));

    JPanel piePanel = new JPanel(new GridLayout(0, 2));
    piePanel.add(usagePieChartPanel);
    piePanel.add(fuelPieChartPanel);
    graphContainer.add(piePanel);
    graphContainer.add(barChartPanel);
    revalidate();
    repaint();
}

From source file:medsavant.uhn.cancer.AddNewCommentDialog.java

private JPanel getOntologyTermsForThisVariant() {
    try {/*from  w ww. ja  v  a2 s  .c  o m*/
        JPanel ontologyTermPanel = new JPanel();
        ontologyTermPanel.setLayout(new BoxLayout(ontologyTermPanel, BoxLayout.Y_AXIS));

        String sessID = LoginController.getSessionID();
        String refName = ReferenceController.getInstance().getCurrentReferenceName();
        if (refName == null) {
            DialogUtils.displayError("Error",
                    "Couldn't obtain name of current reference genome - please login again.");
            dispose();
            return null;
        }
        GeneSet geneSet = MedSavantClient.GeneSetManager.getGeneSet(sessID, refName);
        if (geneSet == null) {
            DialogUtils.displayError("Error",
                    "Couldn't find a gene set for reference " + refName + ". Please check project settings.");
            dispose();
            return null;
        }

        Gene[] genesOverlappingVariant = MedSavantClient.GeneSetManager.getGenesInRegion(sessID, geneSet,
                variantRecord.getChrom(), variantRecord.getStartPosition().intValue(),
                variantRecord.getEndPosition().intValue());
        if (genesOverlappingVariant == null || genesOverlappingVariant.length < 1) {
            //TODO: Here we could allow the user to choose from a list of ALL hpo terms, not just those
            //that are already associated with the variant.
            DialogUtils.displayError("No genes were found associated with this variant " + variantRecord
                    + " in geneSet " + geneSet);
            dispose();
            return null;
        }
        Set<OntologyTerm> ontologyTermSet = new TreeSet<OntologyTerm>();
        for (Gene gene : genesOverlappingVariant) {
            OntologyTerm[] ontologyTerms = MedSavantClient.OntologyManager.getTermsForGene(sessID,
                    UserCommentApp.getDefaultOntologyType(), gene.getName());
            if (ontologyTerms != null && ontologyTerms.length > 0) {
                ontologyTermSet.addAll(Arrays.asList(ontologyTerms));
            }
        }

        selectableOntologyTerms = new SelectableOntologyTerm[ontologyTermSet.size()];
        int i = 0;
        for (OntologyTerm ontologyTerm : ontologyTermSet) {
            selectableOntologyTerms[i] = new SelectableOntologyTerm(ontologyTerm);
            ontologyTermPanel.add(selectableOntologyTerms[i]);
            ++i;
        }
        JScrollPane jsp = new JScrollPane(ontologyTermPanel);
        JPanel p = new JPanel();
        p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
        p.setPreferredSize(new Dimension(mainPanelWidth, mainPanelHeight / 2));
        p.add(jsp);
        return p;
    } catch (Exception ex) {
        ex.printStackTrace();
        LOG.error("Error: ", ex);
        DialogUtils.displayException("Error", ex.getMessage(), ex);
        dispose();
        return null;
    }
}

From source file:serverrobot.DynamicGraph.java

public JPanel createPlatformActualPlot() {
    final TimeSeriesCollection dataset1 = createPlatformRollx2Collection();
    final TimeSeriesCollection dataset2 = createPlatformPitchx2Collection();
    final JFreeChart chart1 = createChart(dataset1, "Roll", -5, 5);
    final JFreeChart chart2 = createChart(dataset2, "Pitch", -5, 5);
    final ChartPanel chartPanel1 = new ChartPanel(chart1);
    final ChartPanel chartPanel2 = new ChartPanel(chart2);
    final JPanel panel = new JPanel(new BorderLayout());
    final GridLayout grid = new GridLayout(2, 1);
    panel.setLayout(grid);//  ww  w. ja  v a2  s  .  c  o m
    panel.add(chartPanel1);
    panel.add(chartPanel2);
    panel.setPreferredSize(new Dimension(1200, 600));
    return panel;
}

From source file:serverrobot.DynamicGraph.java

public JPanel createPlatformPlot() {
    final TimeSeriesCollection dataset1 = createPlatformRollCollection();
    final TimeSeriesCollection dataset2 = createPlatformPitchCollection();
    final JFreeChart chart1 = createChart(dataset1, "Roll", -5, 5);
    final JFreeChart chart2 = createChart(dataset2, "Pitch", -5, 5);
    final ChartPanel chartPanel1 = new ChartPanel(chart1);
    final ChartPanel chartPanel2 = new ChartPanel(chart2);
    final JPanel panel = new JPanel(new BorderLayout());
    final GridLayout grid = new GridLayout(2, 1);
    panel.setLayout(grid);//from   www  .  j a va 2 s .  c  o  m
    panel.add(chartPanel1);
    panel.add(chartPanel2);
    panel.setPreferredSize(new Dimension(1200, 600));
    return panel;
}

From source file:be.ac.ua.comp.scarletnebula.gui.TaggingPanel.java

public TaggingPanel(final Collection<String> initialTags) {
    super(new BorderLayout());

    for (final String tag : initialTags) {
        taglist.addTag(new TagItem(tag));
    }//from  ww  w .j a  va2 s  . c  om
    final BetterTextField inputField = new BetterTextField();
    addTagActionListener = new AddTagActionListener(inputField);
    inputField.addActionListener(addTagActionListener);
    final String hint = "Type a tag and press enter";
    inputField.setPlaceHolder(hint);
    inputField.setToolTipText(hint);
    inputField.setInputVerifier(new TagInputVerifier(inputField));
    inputField.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(0, 0, 5, 0),
            BorderFactory.createBevelBorder(BevelBorder.LOWERED)));

    taglist.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));

    final JScrollPane tagScrollPane = new JScrollPane(taglist);
    tagScrollPane.setBorder(null);

    final JPanel centerPanel = new JPanel(new BorderLayout());
    centerPanel.add(inputField, BorderLayout.NORTH);
    centerPanel.add(tagScrollPane, BorderLayout.CENTER);
    centerPanel.setMaximumSize(new Dimension(250, 500));
    centerPanel.setPreferredSize(new Dimension(200, 200));

    setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS));
    add(Box.createHorizontalGlue());
    add(centerPanel);
    add(Box.createHorizontalGlue());

}

From source file:MainClass.java

MainClass(String title) {
    super(title);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JPanel jp = new JPanel();

    Vector v = new Vector();
    v.add("A");/* w  ww  . ja  va  2s  . c om*/
    v.add("B");
    v.add("C");

    jcb = new JComboBox(v);
    jcb.setEditable(true);

    KeyStroke ks = KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, Event.CTRL_MASK);

    jcb.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(ks, "clearEditor");
    jcb.getActionMap().put("clearEditor", new ClearEditorAction());

    jp.setPreferredSize(new Dimension(200, 35));
    jp.add(jcb);
    getContentPane().add(jp);

    pack();
    setVisible(true);
}

From source file:serverrobot.DynamicGraph.java

public JPanel createPositionPlot() {
    final TimeSeriesCollection dataset1 = createXPositionCollection();
    final TimeSeriesCollection dataset2 = createYPositionCollection();
    final TimeSeriesCollection dataset3 = createZPositionCollection();
    final JFreeChart chart1 = createChart(dataset1, "X", 0.5, 0.75);
    final JFreeChart chart2 = createChart(dataset2, "Y", -0.35, 0.2);
    final JFreeChart chart3 = createChart(dataset3, "Z", 0.5, 0.8);
    final ChartPanel chartPanel1 = new ChartPanel(chart1);
    final ChartPanel chartPanel2 = new ChartPanel(chart2);
    final ChartPanel chartPanel3 = new ChartPanel(chart3);
    final JPanel panel = new JPanel(new BorderLayout());
    final GridLayout grid = new GridLayout(3, 1);
    panel.setLayout(grid);//from w ww  .  java 2s  .  c  o  m
    panel.add(chartPanel1);
    panel.add(chartPanel2);
    panel.add(chartPanel3);
    panel.setPreferredSize(new Dimension(1200, 900));
    return panel;
}

From source file:layout.GridLayoutDemo.java

public void addComponentsToPane(final Container pane) {
    initGaps();//from   www.j ava  2  s.  c o  m
    final JPanel compsToExperiment = new JPanel();
    compsToExperiment.setLayout(experimentLayout);
    JPanel controls = new JPanel();
    controls.setLayout(new GridLayout(2, 3));

    //Set up components preferred size
    JButton b = new JButton("Just fake button");
    Dimension buttonSize = b.getPreferredSize();
    compsToExperiment.setPreferredSize(new Dimension((int) (buttonSize.getWidth() * 2.5) + maxGap,
            (int) (buttonSize.getHeight() * 3.5) + maxGap * 2));

    //Add buttons to experiment with Grid Layout
    compsToExperiment.add(new JButton("Button 1"));
    compsToExperiment.add(new JButton("Button 2"));
    compsToExperiment.add(new JButton("Button 3"));
    compsToExperiment.add(new JButton("Long-Named Button 4"));
    compsToExperiment.add(new JButton("5"));

    //Add controls to set up horizontal and vertical gaps
    controls.add(new Label("Horizontal gap:"));
    controls.add(new Label("Vertical gap:"));
    controls.add(new Label(" "));
    controls.add(horGapComboBox);
    controls.add(verGapComboBox);
    controls.add(applyButton);

    //Process the Apply gaps button press
    applyButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            //Get the horizontal gap value
            String horGap = (String) horGapComboBox.getSelectedItem();
            //Get the vertical gap value
            String verGap = (String) verGapComboBox.getSelectedItem();
            //Set up the horizontal gap value
            experimentLayout.setHgap(Integer.parseInt(horGap));
            //Set up the vertical gap value
            experimentLayout.setVgap(Integer.parseInt(verGap));
            //Set up the layout of the buttons
            experimentLayout.layoutContainer(compsToExperiment);
        }
    });
    pane.add(compsToExperiment, BorderLayout.NORTH);
    pane.add(new JSeparator(), BorderLayout.CENTER);
    pane.add(controls, BorderLayout.SOUTH);
}

From source file:executor.TesterMainGUIMode.java

/**
 * Add chart panel to the frame/*from  ww  w.  j av  a  2  s  .  com*/
 */
private void addChartPanel(JPanel chartPanel) {
    removecurrentChartPanel();

    this.currentChartPanel = chartPanel;
    chartPanel.setPreferredSize(new Dimension(frameWidth, frameHeight - controlPanelHeight));
    chartPanel.setMinimumSize(new Dimension(frameWidth, 200));
    chartPanel.setMaximumSize(new Dimension(Short.MAX_VALUE, Short.MAX_VALUE));
    getContentPane().add(chartPanel);
    this.validate();
    chartPanel.repaint();
}

From source file:io.github.jeremgamer.editor.panels.Panels.java

public Panels(final JFrame frame, final PanelsPanel pp) {
    this.setBorder(BorderFactory.createTitledBorder(""));

    JButton add = null;/*w w  w  .  j  av a2  s.  c  om*/
    try {
        add = new JButton(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("add.png"))));
    } catch (IOException e) {
        e.printStackTrace();
    }
    add.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            try {
                JOptionPane jop = new JOptionPane();
                @SuppressWarnings("static-access")
                String name = jop.showInputDialog((JFrame) SwingUtilities.windowForComponent(panelList),
                        "Nommez le panneau :", "Crer un panneau", JOptionPane.QUESTION_MESSAGE);

                if (name != null) {
                    for (int i = 0; i < data.getSize(); i++) {
                        if (data.get(i).equals(name)) {
                            name += "1";
                        }
                    }
                    data.addElement(name);
                    new PanelSave(name);
                    PanelsPanel.updateLists();
                    mainPanel.addItem(name);
                }
            } catch (IOException e) {
                e.printStackTrace();
            }

        }

    });

    JButton remove = null;
    try {
        remove = new JButton(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("remove.png"))));
    } catch (IOException e) {
        e.printStackTrace();
    }
    remove.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            try {
                if (panelList.getSelectedValue() != null) {
                    File file = new File("projects/" + Editor.getProjectName() + "/panels/"
                            + panelList.getSelectedValue() + "/" + panelList.getSelectedValue() + ".rbd");
                    JOptionPane jop = new JOptionPane();
                    @SuppressWarnings("static-access")
                    int option = jop.showConfirmDialog((JFrame) SwingUtilities.windowForComponent(panelList),
                            "tes-vous sr de vouloir supprimer ce panneau?", "Avertissement",
                            JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);

                    if (option == JOptionPane.OK_OPTION) {
                        if (panelList.getSelectedValue().equals(pp.getFileName())) {
                            pp.setFileName("");
                        }
                        pp.hide();
                        file.delete();
                        File parent = new File(file.getParent());
                        for (File img : FileUtils.listFiles(parent, TrueFileFilter.INSTANCE,
                                TrueFileFilter.INSTANCE)) {
                            img.delete();
                        }
                        parent.delete();
                        mainPanel.removeItem(panelList.getSelectedValue());
                        data.remove(panelList.getSelectedIndex());
                        ActionPanel.updateLists();
                        PanelsPanel.updateLists();
                    }
                }
            } catch (NullPointerException npe) {
                npe.printStackTrace();
            }

        }

    });

    JPanel buttons = new JPanel();
    buttons.setLayout(new BoxLayout(buttons, BoxLayout.LINE_AXIS));
    buttons.add(add);
    buttons.add(remove);

    mainPanel.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            @SuppressWarnings("unchecked")
            JComboBox<String> combo = (JComboBox<String>) event.getSource();
            GeneralSave gs = new GeneralSave();
            try {
                gs.load(new File("projects/" + Editor.getProjectName() + "/general.rbd"));
                gs.set("mainPanel", combo.getSelectedItem());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    });

    updateList();
    panelList.addMouseListener(new MouseAdapter() {
        @SuppressWarnings("unchecked")
        public void mouseClicked(MouseEvent evt) {
            JList<String> list = (JList<String>) evt.getSource();
            if (evt.getClickCount() == 2) {
                int index = list.locationToIndex(evt.getPoint());
                if (isOpen == false) {
                    pp.load(new File("projects/" + Editor.getProjectName() + "/panels/"
                            + list.getModel().getElementAt(index) + "/" + list.getModel().getElementAt(index)
                            + ".rbd"));
                    PanelsPanel.updateLists();
                    pp.show();
                    previousSelection = list.getSelectedValue();
                    isOpen = true;
                } else {
                    try {
                        if (previousSelection.equals(list.getModel().getElementAt(index))) {
                            pp.hide();
                            previousSelection = list.getSelectedValue();
                            list.clearSelection();
                            isOpen = false;
                        } else {
                            pp.hideThenShow();
                            previousSelection = list.getSelectedValue();
                            pp.load(new File("projects/" + Editor.getProjectName() + "/panels/"
                                    + list.getModel().getElementAt(index) + "/"
                                    + list.getModel().getElementAt(index) + ".rbd"));
                            PanelsPanel.updateLists();
                        }
                    } catch (NullPointerException npe) {
                        pp.hide();
                        list.clearSelection();
                    }
                }
            } else if (evt.getClickCount() == 3) {
                int index = list.locationToIndex(evt.getPoint());
                if (isOpen == false) {
                    pp.load(new File("projects/" + Editor.getProjectName() + "/panels/"
                            + list.getModel().getElementAt(index) + "/" + list.getModel().getElementAt(index)
                            + ".rbd"));
                    PanelsPanel.updateLists();
                    pp.show();
                    previousSelection = list.getSelectedValue();
                    isOpen = true;
                } else {
                    try {
                        if (previousSelection.equals(list.getModel().getElementAt(index))) {
                            pp.hide();
                            previousSelection = list.getSelectedValue();
                            list.clearSelection();
                            isOpen = false;
                        } else {
                            pp.hideThenShow();
                            previousSelection = list.getSelectedValue();
                            pp.load(new File("projects/" + Editor.getProjectName() + "/panels/"
                                    + list.getModel().getElementAt(index) + "/"
                                    + list.getModel().getElementAt(index) + ".rbd"));
                            PanelsPanel.updateLists();
                        }
                    } catch (NullPointerException npe) {
                        pp.hide();
                        list.clearSelection();
                    }
                }
            }
        }
    });
    JScrollPane listPane = new JScrollPane(panelList);
    listPane.getVerticalScrollBar().setUnitIncrement(Editor.SCROLL_SPEED);
    this.setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
    this.add(buttons);
    this.add(listPane);

    JPanel mainPanelInput = new JPanel();
    mainPanelInput.setPreferredSize(new Dimension(280, 35));
    mainPanelInput.setMaximumSize(new Dimension(280, 35));
    mainPanelInput.add(new JLabel("Panneau principal:"));
    mainPanel.setPreferredSize(new Dimension(150, 27));
    mainPanelInput.add(mainPanel);
    this.add(mainPanelInput);
}