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:gov.llnl.lc.infiniband.opensm.plugin.gui.bargraph.AnimatedBarGraph.java

public AnimatedBarGraph(BarGraphDataSeries dataSeries, int mSecs, boolean cycle) {
    super(dataSeries.getGraphTitle());

    JPanel chartPanel = createPanel(dataSeries, mSecs, cycle);
    chartPanel.setPreferredSize(new Dimension(800, 400));
    setContentPane(chartPanel);//w  w w  .j a v a2s.co m
}

From source file:org.jfree.chart.demo.CandlestickChartDemo1.java

public CandlestickChartDemo1(String s) {
    super(s);//w  w w . ja  v a 2 s .  c o m
    JPanel jpanel = createDemoPanel();
    jpanel.setPreferredSize(new Dimension(500, 270));
    setContentPane(jpanel);
}

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

/**
 * For posting new comments. Presents dialog with an ontology term selector,
 * with the selectedOntologyTerm selected by default.
 *//*  ww w  .  ja va  2  s. c om*/
public AddNewCommentDialog(JFrame parentFrame, VariantRecord vr, OntologyTerm selectedOntologyTerm) { //post new  message for
    super(parentFrame);
    this.selectedOntologyTerm = selectedOntologyTerm;
    this.variantRecord = vr;
    Dimension pd = parentFrame.getSize();
    mainPanelWidth = Math.max(MINIMUM_WIDTH, pd.width / 2);
    mainPanelHeight = Math.max(MINIMUM_HEIGHT, pd.height / 2);
    JPanel mainPanel = getMainPanel();
    mainPanel.setPreferredSize(new Dimension(mainPanelWidth, mainPanelHeight));
    this.add(mainPanel);
    this.pack();
    this.setModal(true);

}

From source file:org.jfree.chart.demo.ThumbnailDemo1.java

public ThumbnailDemo1(String s) {
    super(s);/*from w  w w . j  ava  2  s. co  m*/
    JPanel jpanel = createDemoPanel();
    jpanel.setPreferredSize(new Dimension(500, 270));
    setContentPane(jpanel);
}

From source file:es.emergya.ui.plugins.LayerSelectionDialog.java

public LayerSelectionDialog(CustomMapView gmv) {
    super();/*from ww  w.  jav  a  2 s.c om*/
    self = this;
    this.setTitle("Otras Capas");
    actualizando = new JLabel(LogicConstants.getIcon("anim_actualizando"));
    this.setAlwaysOnTop(true);
    this.mv = gmv;
    this.layers = new ArrayList<LayerElement>();
    try {
        setIconImage(((BasicWindow) GoClassLoader.getGoClassLoader().load(BasicWindow.class)).getIconImage());
    } catch (Throwable e1) {
        LOG.error("Couldn't find icon image", e1);
    }

    JPanel base = new JPanel();
    base.setPreferredSize(new Dimension(240, 150));
    base.setBackground(Color.WHITE);
    base.setLayout(new BoxLayout(base, BoxLayout.Y_AXIS));
    base.add(new JLabel(i18n.getString("map.layers.avaliable")));
    list = new JPanel();
    list.setLayout(new BoxLayout(list, BoxLayout.Y_AXIS));
    list.add(actualizando);
    list.setBackground(Color.WHITE);
    // list.setPreferredSize(new Dimension(100, 100));
    final JScrollPane scrollPane = new JScrollPane(list);
    scrollPane.setBackground(Color.WHITE);

    base.add(scrollPane);

    mv.addComponentListener(new ComponentAdapter() {

        @Override
        public void componentShown(ComponentEvent e) {
        }
    });

    add(base);
    pack();
}

From source file:SplashScreen.java

public SplashScreen(final BufferedImage img) {
    JPanel panel = new JPanel() {
        public void paintComponent(Graphics g) {
            super.paintComponent(g);
            Graphics2D g2d = (Graphics2D) g.create();

            g2d.drawImage(img, 0, 0, img.getWidth(), img.getHeight(), SplashScreen.this);
        }//from   www  .  j ava 2s.co  m
    };
    panel.setPreferredSize(new Dimension(img.getWidth(), img.getHeight()));

    Container content = getContentPane();
    content.setLayout(new BorderLayout());
    content.add(panel, BorderLayout.NORTH);
    content.add(label = new JLabel(), BorderLayout.CENTER);
    content.add(bar = new JProgressBar(), BorderLayout.SOUTH);
    pack();
    setLocationRelativeTo(null);
}

From source file:de.rub.syssec.saaf.gui.frame.CfgSelectorFrame.java

/**
 * A frame to generate and open Control Flow Graphs. CFGs are created using mxGraph
 * and are saved as PNGs./*from   w  w w.  j ava  2s. co  m*/
 * 
 * @param smaliClass the smali class to select methods from
 */
public CfgSelectorFrame(ClassInterface smaliClass) {
    super(smaliClass.getFullClassName(true), true, true, true, true);
    this.smaliClass = smaliClass;

    listModel = new MethodTableModel(smaliClass);
    list.setModel(listModel);
    list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    list.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent event) {
            int viewRow = list.getSelectedRow();
            if (viewRow <= 0) {
                showButton.setEnabled(false);
            } else {
                showButton.setEnabled(true);
            }
        }
    });

    JScrollPane listScrollPane = new JScrollPane(list);

    ActionListener al = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (e.getActionCommand().equals(SHOW_OPERATION)) {
                generateAndShowCfg(true);
            } else if (e.getActionCommand().equals(GENERATE_OPERATION)) {
                generateAndShowCfg(false);
            }
        }
    };

    generateButton = new JButton(GENERATE_OPERATION);
    generateButton.setActionCommand(GENERATE_OPERATION);
    generateButton.addActionListener(al);
    showButton = new JButton(SHOW_OPERATION);
    showButton.setEnabled(false);
    showButton.addActionListener(al);

    saveCfgCheckBox = new JCheckBox("Save a copy");
    saveCfgCheckBox.setToolTipText("Save a copy in the configured CFG folder upon generation.");

    JPanel buttonPane = new JPanel();
    buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS));
    buttonPane.add(generateButton);
    buttonPane.add(saveCfgCheckBox);
    buttonPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    JPanel filler = new JPanel();
    filler.setPreferredSize(new Dimension(10, 10));
    buttonPane.add(filler);
    buttonPane.add(showButton);

    add(listScrollPane, BorderLayout.CENTER);
    add(buttonPane, BorderLayout.PAGE_END);

    this.setPreferredSize(new Dimension(500, 250));
    this.pack();
    this.setVisible(true);
}

From source file:GCWrapper.java

/**
 * Creates and lays out components in the container. See the comments below
 * for an organizational overview by panel.
 *//*from   ww  w. java  2s. c  o  m*/
private void initComponents(Container c) {
    // +=c=====================================================+
    // ++=gcPanel==============================================+
    // ++ [gcSelection] +
    // ++=capsPanel============================================+
    // +++=imageCapsPanel======================================+
    // +++ [imageAccelerated] +
    // +++ [imageTrueVolatile] +
    // +++=bufferCapsPanel=====================================+
    // ++++=bufferAccessCapsPanel==============================+
    // +++++=flippingPanel=====================================+
    // +++++ [flipping] +
    // +++++=fsPanel===========================================+
    // +++++ [indentPanel][fullScreen] +
    // +++++=mbPanel===========================================+
    // +++++ [indentPanel][multiBuffer] +
    // ++++=buffersPanel=======================================+
    // +++++=fbPanel===============+=bbPanel===================+
    // +++++ + +
    // +++++ [fbAccelerated] + [bbAccelerated] +
    // +++++ + +
    // +++++ [fbTrueVolatile] + [bbTrueVolatile] +
    // +++++ + +
    // +=======================================================+
    c.setLayout(new BorderLayout());
    // Graphics Config
    JPanel gcPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
    c.add(gcPanel, BorderLayout.NORTH);
    gcSelection.setPreferredSize(new Dimension(400, 30));
    gcPanel.add(gcSelection);
    // Capabilities
    JPanel capsPanel = new JPanel(new BorderLayout());
    c.add(capsPanel, BorderLayout.CENTER);
    // Image Capabilities
    JPanel imageCapsPanel = new JPanel(new GridLayout(2, 1));
    capsPanel.add(imageCapsPanel, BorderLayout.NORTH);
    imageCapsPanel.setBorder(BorderFactory.createTitledBorder("Image Capabilities"));
    imageAccelerated.setEnabled(false);
    imageCapsPanel.add(imageAccelerated);
    imageTrueVolatile.setEnabled(false);
    imageCapsPanel.add(imageTrueVolatile);
    // Buffer Capabilities
    JPanel bufferCapsPanel = new JPanel(new BorderLayout());
    capsPanel.add(bufferCapsPanel, BorderLayout.CENTER);
    bufferCapsPanel.setBorder(BorderFactory.createTitledBorder("Buffer Capabilities"));
    // Buffer Access
    JPanel bufferAccessCapsPanel = new JPanel(new GridLayout(3, 1));
    bufferAccessCapsPanel.setPreferredSize(new Dimension(300, 88));
    bufferCapsPanel.add(bufferAccessCapsPanel, BorderLayout.NORTH);
    // Flipping
    JPanel flippingPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
    bufferAccessCapsPanel.add(flippingPanel);
    flippingPanel.add(flipping);
    flipping.setEnabled(false);
    flippingPanel.add(flippingMethod);
    // Full-screen
    JPanel fsPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
    bufferAccessCapsPanel.add(fsPanel);
    JPanel indentPanel = new JPanel();
    indentPanel.setPreferredSize(new Dimension(30, 30));
    fsPanel.add(indentPanel);
    fsPanel.add(fullScreen);
    fullScreen.setEnabled(false);
    // Multi-buffering
    JPanel mbPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
    bufferAccessCapsPanel.add(mbPanel);
    indentPanel = new JPanel();
    indentPanel.setPreferredSize(new Dimension(30, 30));
    mbPanel.add(indentPanel);
    mbPanel.add(multiBuffer);
    multiBuffer.setEnabled(false);
    // Front and Back Buffer Capabilities
    JPanel buffersPanel = new JPanel(new GridLayout(1, 2));
    bufferCapsPanel.add(buffersPanel, BorderLayout.CENTER);
    // Front Buffer
    JPanel fbPanel = new JPanel(new GridLayout(2, 1));
    fbPanel.setBorder(BorderFactory.createTitledBorder("Front Buffer"));
    buffersPanel.add(fbPanel);
    fbPanel.add(fbAccelerated);
    fbAccelerated.setEnabled(false);
    fbPanel.add(fbTrueVolatile);
    fbTrueVolatile.setEnabled(false);
    // Back Buffer
    JPanel bbPanel = new JPanel(new GridLayout(2, 1));
    bbPanel.setPreferredSize(new Dimension(250, 80));
    bbPanel.setBorder(BorderFactory.createTitledBorder("Back and Intermediate Buffers"));
    buffersPanel.add(bbPanel);
    bbPanel.add(bbAccelerated);
    bbAccelerated.setEnabled(false);
    bbPanel.add(bbTrueVolatile);
    bbTrueVolatile.setEnabled(false);
}

From source file:gov.llnl.lc.infiniband.opensm.plugin.gui.chart.AdvancedXY_PlotPanel.java

private void initChart(XY_PlotPanel pPanel) {
    this.plotPanel = pPanel;
    this.chartPanel = pPanel.getChartPanel();
    if (pPanel instanceof SimpleXY_PlotPanel) {
        this.setTitle(((SimpleXY_PlotPanel) pPanel).getTitle());
    }//from   w ww. j  a v a  2s.com

    JFreeChart chart = chartPanel.getChart();
    XYPlot plot = (XYPlot) chart.getPlot();

    // how many data sets will there be (may not exist yet, cause swing worker may still be constructing them)
    int numRows = 2; // enough for counts, and delta counts
    if ((XY_PlotType.ADV_PORT_UTIL_PLUS.equals(getType())))
        numRows = 4;
    boolean includeExtra = numRows > MAX_DATASETS / 2 ? true : false;

    int rowSize = includeExtra ? MAX_DS_SIZE : MAX_DS_SIZE / 2 + 19; // extra for padding
    NumDataSets = numRows;

    // build the table model from the data sets, then build the table and slider

    // see "chartProgress()" method
    chart.addProgressListener(this);

    this.chartPanel.setPreferredSize(new java.awt.Dimension(750, 300));
    this.chartPanel.setDomainZoomable(true);
    this.chartPanel.setRangeZoomable(true);
    Border border = BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4),
            BorderFactory.createEtchedBorder());
    this.chartPanel.setBorder(border);
    add(this.chartPanel);

    JPanel dashboard = new JPanel(new BorderLayout());
    dashboard.setPreferredSize(new Dimension(400, rowSize));
    dashboard.setBorder(BorderFactory.createEmptyBorder(0, 4, 4, 4));

    this.model = new XY_PlotTableModel(numRows);

    // initialize the model, and table, here
    //    this.model.setValueAt("name", 0, 1);
    this.model.setValueAt(new Double("0.00"), 0, 1);
    this.model.setValueAt(new Double("0.00"), 0, 2);
    //    this.model.setValueAt("units", 0, 3);
    JTable table = new JTable(this.model);

    // the columns are name, time, value, units.  both name and units are strings
    // so need special renderers for time and value

    TableCellRenderer renderer1 = new DateCellRenderer(new SimpleDateFormat("HH:mm:ss"));
    TableCellRenderer renderer2 = new NumberCellRenderer();
    table.getColumnModel().getColumn(1).setCellRenderer(renderer1);
    table.getColumnModel().getColumn(2).setCellRenderer(renderer2);
    JScrollPane scroller = new JScrollPane(table);
    dashboard.add(scroller);

    this.slider = new JSlider(0, 100, 10);
    this.slider.addChangeListener(this);
    dashboard.add(this.slider, BorderLayout.SOUTH);
    add(dashboard, BorderLayout.SOUTH);

    //     XYPlot plot = (XYPlot) chart.getPlot();

    plot.setDomainCrosshairLockedOnData(true);
    plot.setRangeCrosshairVisible(false);
    plot.setDomainCrosshairVisible(true);
}

From source file:GeMSE.Visualization.ElbowPlot.java

public void Plot(ArrayList<Double[]> pvData, ArrayList<Double[]> dData, int cut) {
    double maxY = 0;

    float[] secYColor = new float[3];
    Color.RGBtoHSB(153, 245, 255, secYColor);

    float[] priYColor = new float[3];
    Color.RGBtoHSB(255, 255, 255, priYColor);

    float[] cutColor = new float[3];
    Color.RGBtoHSB(255, 255, 0, cutColor);

    //create the series - add some dummy data
    XYSeries pvSeries = new XYSeries("Percentage of variance        ");
    for (int i = 1; i < pvData.size(); i++) {
        pvSeries.add(pvData.get(i)[0], pvData.get(i)[1]);
        maxY = Math.max(maxY, pvData.get(i)[1]);
    }/* w  w w.  j  a v  a  2  s  . c om*/

    XYSeries dSeries = new XYSeries("Percentage of differences between slopes        ");
    for (int i = 0; i < dData.size(); i++)
        dSeries.add(dData.get(i)[0], dData.get(i)[1]);

    XYSeries cutSeries = new XYSeries("Cut        ");
    cutSeries.add(cut, 0.0);
    cutSeries.add(cut, maxY);

    //create the datasets
    XYSeriesCollection pvDataSeries = new XYSeriesCollection();
    pvDataSeries.addSeries(pvSeries);

    XYSeriesCollection cutDataSeries = new XYSeriesCollection();
    cutDataSeries.addSeries(cutSeries);

    XYSeriesCollection dDataSeries = new XYSeriesCollection();
    dDataSeries.addSeries(dSeries);

    //construct the plot
    XYPlot plot = new XYPlot();
    plot.setDataset(0, pvDataSeries);
    plot.setDataset(1, cutDataSeries);
    plot.setDataset(2, dDataSeries);

    // use XYSplineRenderer if you want to smooth the lines.
    XYLineAndShapeRenderer pvRenderer = new XYLineAndShapeRenderer();
    pvRenderer.setSeriesPaint(0, Color.getHSBColor(priYColor[0], priYColor[1], priYColor[2]));

    BasicStroke dstroke = new BasicStroke(2.0f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_ROUND, 1.0f,
            new float[] { 1.0f, 10.0f }, 0.0f);
    XYLineAndShapeRenderer dRenderer = new XYLineAndShapeRenderer();
    dRenderer.setSeriesPaint(0, Color.getHSBColor(secYColor[0], secYColor[1], secYColor[2]));
    dRenderer.setSeriesStroke(0, dstroke);

    BasicStroke cutStoke = new BasicStroke(4);
    // use XYSplineRenderer if you want to smooth the lines.
    //XYSplineRenderer cutRenderer = new XYSplineRenderer();
    XYLineAndShapeRenderer cutRenderer = new XYLineAndShapeRenderer();
    cutRenderer.setSeriesPaint(0, Color.getHSBColor(cutColor[0], cutColor[1], cutColor[2]));
    cutRenderer.setSeriesStroke(0, cutStoke);

    plot.setRenderer(0, pvRenderer);
    plot.setRenderer(1, cutRenderer);
    plot.setRenderer(2, dRenderer);

    plot.setRangeAxis(0, new NumberAxis("\n\nPercentage of Variance"));
    plot.setRangeAxis(1, new NumberAxis("Percentage of Difference Between Slopes"));
    plot.setDomainAxis(new NumberAxis("Number of Clusters\n\n"));

    //Map the data to the appropriate axis
    plot.mapDatasetToRangeAxis(0, 0);
    plot.mapDatasetToRangeAxis(1, 0);
    plot.mapDatasetToRangeAxis(2, 1);

    float[] hsbValues = new float[3];
    Color.RGBtoHSB(16, 23, 67, hsbValues);
    plot.setBackgroundPaint(Color.getHSBColor(hsbValues[0], hsbValues[1], hsbValues[2]));

    Font axisLabelFont = new Font("Dialog", Font.PLAIN, 14);
    Font axisTickLabelFont = new Font("Dialog", Font.PLAIN, 12);
    Font legendFont = new Font("Dialog", Font.PLAIN, 14);

    plot.setDomainGridlinePaint(Color.gray);
    plot.setRangeGridlinePaint(Color.gray);

    plot.getDomainAxis().setTickLabelPaint(Color.white);
    plot.getDomainAxis().setLabelPaint(Color.white);
    plot.getDomainAxis().setLabelFont(axisLabelFont);
    plot.getDomainAxis().setTickLabelFont(axisTickLabelFont);

    plot.getRangeAxis().setTickLabelPaint(Color.getHSBColor(priYColor[0], priYColor[1], priYColor[2]));
    plot.getRangeAxis().setLabelPaint(Color.getHSBColor(priYColor[0], priYColor[1], priYColor[2]));
    plot.getRangeAxis().setLabelFont(axisLabelFont);
    plot.getRangeAxis().setTickLabelFont(axisTickLabelFont);

    plot.getRangeAxis(1).setTickLabelPaint(Color.getHSBColor(secYColor[0], secYColor[1], secYColor[2]));
    plot.getRangeAxis(1).setLabelPaint(Color.getHSBColor(secYColor[0], secYColor[1], secYColor[2]));
    plot.getRangeAxis(1).setLabelFont(axisLabelFont);
    plot.getRangeAxis(1).setTickLabelFont(axisTickLabelFont);

    //generate the chart
    JFreeChart chart = new JFreeChart("\nSuggested number of clusters determined using Elbow method", getFont(),
            plot, true);

    chart.getTitle().setPaint(Color.white);
    chart.getLegend().setBackgroundPaint(Color.black);
    chart.getLegend().setItemPaint(Color.white);
    chart.getLegend().setPosition(RectangleEdge.BOTTOM);
    chart.getLegend().setItemFont(legendFont);

    float[] hsbValues2 = new float[3];
    Color.RGBtoHSB(36, 43, 87, hsbValues2);
    chart.setBackgroundPaint(Color.getHSBColor(hsbValues2[0], hsbValues2[1], hsbValues2[2]));
    JPanel chartPanel = new ChartPanel(chart);

    GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
    chartPanel.setPreferredSize(
            new java.awt.Dimension((int) Math.round((gd.getDisplayMode().getWidth() * 1.5) / 3.0),
                    (int) Math.round((gd.getDisplayMode().getHeight() * 1.5) / 3.0)));

    setContentPane(chartPanel);
}