Example usage for javax.swing JPanel validate

List of usage examples for javax.swing JPanel validate

Introduction

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

Prototype

public void validate() 

Source Link

Document

Validates this container and all of its subcomponents.

Usage

From source file:com.enderville.enderinstaller.ui.Installer.java

private void buildOptionsPane() {

    JPanel p = getMainPane();
    p.removeAll();/*from   ww  w.j  a  v  a 2  s. c o  m*/

    JPanel leftPane = new JPanel(new MigLayout(new LC().fill(), new AC().index(1).fill().grow(),
            new AC().index(0).fill().grow().index(1).fill().grow()));
    leftPane.add(new JLabel("Please select which optional mods you would like to install."),
            new CC().spanX().wrap());
    leftPane.add(new JLabel("Presets: "), new CC());
    leftPane.add(getPresetDropdown(), new CC().grow().wrap());
    leftPane.add(new JScrollPane(getModTree()), new CC().spanX().spanY().grow().wrap());

    p.setLayout(new MigLayout(new LC().fill(), new AC().index(0).fill().grow().index(1).fill().grow(),
            new AC().fill()));
    p.add(leftPane, new CC().grow().width(":300:"));
    p.add(getModDescriptionPane(), new CC().grow().width(":300:300").wrap());

    p.validate();
    p.repaint();
}

From source file:MonteCarloWindowLogic.java

static void drawPointsOnChart(JPanel panelWhenInside, ArrayList<Point2D> convexHull, ArrayList<Point2D> hits,
        ArrayList<Point2D> miss) {
    panelWhenInside.removeAll();/*from w w  w .  ja  v  a 2s  .  c  o  m*/
    panelWhenInside.setLayout(new java.awt.BorderLayout());

    XYSeries seriersHits = new XYSeries("Hits");
    convertArrayListToXYSeries(seriersHits, hits);

    XYSeries seriersMiss = new XYSeries("Miss");
    convertArrayListToXYSeries(seriersMiss, miss);
    //TODO refactor this, to handling hits, miss and than convex hull

    int pairsNumber = 0;
    if (convexHull != null)
        pairsNumber = convexHull.size() - 1;
    XYSeries covnexHullDivideOnPiars[] = new XYSeries[pairsNumber];

    for (int i = 0; i < covnexHullDivideOnPiars.length; i++) {
        covnexHullDivideOnPiars[i] = new XYSeries("Convex hull pair " + i);
    }

    if (convexHull != null) {
        divideOnPairsAndConvertConvexHullIntoSeries(covnexHullDivideOnPiars, convexHull);
    }

    // Add the seriersAllPoints to your data set
    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(seriersHits);
    dataset.addSeries(seriersMiss);

    for (int i = 0; i < covnexHullDivideOnPiars.length; i++) {
        dataset.addSeries(covnexHullDivideOnPiars[i]);
    }

    // Generate the graph
    JFreeChart chart = ChartFactory.createXYLineChart(null, // Title
            null, // x-axis Label
            null, // y-axis Label
            dataset, // Dataset
            PlotOrientation.VERTICAL, // Plot Orientation
            false, // Show Legend
            false, // Use tooltips
            false // Configure chart to generate URLs?
    );

    final XYPlot plot = chart.getXYPlot();
    ChartPanel chartPanel = new ChartPanel(chart);
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesPaint(0, Color.GREEN);
    renderer.setSeriesLinesVisible(0, false);
    renderer.setSeriesShape(0, ShapeUtilities.createDiamond(3));

    renderer.setSeriesPaint(1, Color.RED);
    renderer.setSeriesLinesVisible(1, false);
    renderer.setSeriesShape(1, ShapeUtilities.createDiamond(3));

    for (int i = 2; i <= covnexHullDivideOnPiars.length + 1; i++) {
        renderer.setSeriesPaint(i, Color.black);
        renderer.setSeriesLinesVisible(i, true);
        renderer.setSeriesStroke(i, new BasicStroke(1.0f));
    }

    plot.setRenderer(renderer);

    panelWhenInside.add(chartPanel, BorderLayout.CENTER);
    panelWhenInside.validate();
}

From source file:layout.FlowLayoutDemo.java

public void addComponentsToPane(final Container pane) {
    final JPanel compsToExperiment = new JPanel();
    compsToExperiment.setLayout(experimentLayout);
    experimentLayout.setAlignment(FlowLayout.TRAILING);
    JPanel controls = new JPanel();
    controls.setLayout(new FlowLayout());

    LtoRbutton = new JRadioButton(LtoR);
    LtoRbutton.setActionCommand(LtoR);/*from   w  w w .j  a v  a2s  .  c  o  m*/
    LtoRbutton.setSelected(true);
    RtoLbutton = new JRadioButton(RtoL);
    RtoLbutton.setActionCommand(RtoL);

    //Add buttons to the experiment 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"));
    //Left to right component orientation is selected by default
    compsToExperiment.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);

    //Add controls to set up the component orientation in the experiment layout
    final ButtonGroup group = new ButtonGroup();
    group.add(LtoRbutton);
    group.add(RtoLbutton);
    controls.add(LtoRbutton);
    controls.add(RtoLbutton);
    controls.add(applyButton);

    //Process the Apply component orientation button press
    applyButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            String command = group.getSelection().getActionCommand();
            //Check the selection
            if (command.equals("Left to right")) {
                compsToExperiment.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
            } else {
                compsToExperiment.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
            }
            //update the experiment layout
            compsToExperiment.validate();
            compsToExperiment.repaint();
        }
    });
    pane.add(compsToExperiment, BorderLayout.CENTER);
    pane.add(controls, BorderLayout.SOUTH);
    ;
}

From source file:com.smanempat.controller.ControllerEvaluation.java

private void showChart(int nilaiK, double[][] evalValue, JPanel panelChart, JPanel panelChart1,
        JPanel panelChart2) {/*from   w  w w . j av a  2  s  .  c o  m*/
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    dataset.addValue(evalValue[0][0], "Kriteria", "Accuracy");
    dataset.addValue(evalValue[1][0], "Kriteria", "Recall");
    dataset.addValue(evalValue[2][0], "Kriteria", "Precision");

    JFreeChart lineChart = ChartFactory.createLineChart("Grafik Hasil Pengujian Single Test", "Kriteria",
            "Persentase", dataset, PlotOrientation.VERTICAL, false, true, false);

    CategoryPlot linePlot = lineChart.getCategoryPlot();
    LineAndShapeRenderer lineRender = new LineAndShapeRenderer();
    lineRender.setBaseShapesVisible(true);
    lineRender.setDrawOutlines(true);
    lineRender.setUseFillPaint(true);
    lineRender.setBaseFillPaint(Color.white);
    lineRender.setSeriesStroke(0, new BasicStroke(1.0f));
    lineRender.setSeriesOutlineStroke(0, new BasicStroke(5.0f));
    lineRender.setSeriesShape(0, new Ellipse2D.Double(-5.0, -5.0, 10.0, 10.0));
    linePlot.setRenderer(lineRender);

    ChartPanel cp = new ChartPanel(lineChart);
    panelChart.removeAll();
    panelChart.add(cp);
    panelChart.validate();

}

From source file:com.smanempat.controller.ControllerEvaluation.java

private void showChart(int[] tempK, double[][] evalValue, JPanel panelChart, JPanel panelChart1,
        JPanel panelChart2) {/*from w ww .ja v a2  s . c  o m*/
    final XYSeries accuracy = new XYSeries("Accuracy");
    final XYSeries recall = new XYSeries("Recall");
    final XYSeries precision = new XYSeries("Precision");
    final XYSeriesCollection accColect = new XYSeriesCollection();

    System.out.println("tempk panjangnya " + tempK.length);
    for (int i = 0; i < tempK.length; i++) {
        accuracy.add(tempK[i], evalValue[0][i]);
        recall.add(tempK[i], evalValue[1][i]);
        precision.add(tempK[i], evalValue[2][i]);
        System.out.println("Akurasi K ke-" + tempK[i] + "= " + evalValue[0][i]);
    }
    accColect.addSeries(accuracy);
    accColect.addSeries(recall);
    accColect.addSeries(precision);
    JFreeChart xyLineChart = ChartFactory.createXYLineChart("Grafik Hasil Pengujian Multi Testing",
            "Number of Nearest Neighbor", "Persentase", accColect, PlotOrientation.VERTICAL, true, true, false);
    final XYPlot xyPlot = xyLineChart.getXYPlot();
    XYLineAndShapeRenderer xyRender = new XYLineAndShapeRenderer();
    xyRender.setSeriesPaint(0, Color.RED);
    xyRender.setSeriesPaint(1, Color.GREEN);
    xyRender.setSeriesPaint(2, Color.BLUE);
    xyRender.setSeriesStroke(0, new BasicStroke(4.0f));
    xyRender.setSeriesStroke(1, new BasicStroke(3.0f));
    xyRender.setSeriesStroke(2, new BasicStroke(2.0f));
    xyPlot.setRenderer(xyRender);
    ChartPanel cp = new ChartPanel(xyLineChart);
    panelChart.removeAll();
    panelChart.add(cp);
    panelChart.validate();

}

From source file:com.enderville.enderinstaller.ui.Installer.java

private void loadModDescription(String modName) {
    JPanel p = getModDescriptionPane();
    p.removeAll();//  w ww . j  av a2  s .co  m
    p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));

    final String extras = InstallerConfig.getExtraModsFolder();
    final String modFolderName = FilenameUtils.concat(extras, modName);
    File modFolder = new File(modFolderName);
    if (!modFolder.exists()) {
        LOGGER.error("Mod folder for " + modName + " does not exist.");
    }
    File descrFile = new File(FilenameUtils.concat(modFolderName, "description.txt"));
    File imgFile = new File(FilenameUtils.concat(modFolderName, "image.png"));
    if (!descrFile.exists() && !imgFile.exists()) {
        p.add(new JLabel("<html>No description for:<br>" + modName + "</html>"));
    } else {
        if (imgFile.exists()) {
            try {
                JLabel label = new JLabel();
                BufferedImage img = ImageIO.read(imgFile);
                label.setIcon(new ImageIcon(img));
                p.add(label);
            } catch (IOException e) {
                LOGGER.error("Error reading image file: " + imgFile.getPath(), e);
            }
        }
        if (descrFile.exists()) {
            StringBuilder buffer = new StringBuilder();
            try {
                BufferedReader r = new BufferedReader(new FileReader(descrFile));
                String l = null;
                while ((l = r.readLine()) != null) {
                    buffer.append(l + "\n");
                }
                r.close();
                JEditorPane area = new JEditorPane();
                area.setContentType("text/html");
                area.setText(buffer.toString());
                area.setEditable(false);
                area.addHyperlinkListener(this);
                area.setCaretPosition(0);
                p.add(new JScrollPane(area));
            } catch (IOException e) {
                LOGGER.error("Error reading description file: " + descrFile.getPath(), e);
            }
        }
    }

    p.validate();
    p.repaint();
}

From source file:beproject.MainGUI.java

void createTagCloud() throws SQLException {
    TreeMap tmp = getFrequentWords();
    Cloud cld = new Cloud();
    JPanel tmpPanel = new JPanel();
    FlowLayout t1 = new FlowLayout();
    tmpPanel.setPreferredSize(new Dimension(512, 512));
    tmpPanel.setLayout(t1);/*  w w w .  j  a  v  a2 s  .c om*/
    tmpPanel.setBounds(0, 0, 512, 512);
    //FlowLayout lm=(FlowLayout) tmpPanel.getLayout();
    for (int i = 0; i < 40 && !tmp.isEmpty(); i++) {
        Map.Entry mp = tmp.pollFirstEntry();
        Tag t = new Tag((String) mp.getKey(), (int) (mp.getValue()));
        cld.addTag(t);
    }
    Random rand = new Random();
    for (Tag tag : cld.tags()) {
        final JLabel label = new JLabel(tag.getName());
        label.setOpaque(false);
        label.setFont(label.getFont().deriveFont(rand.nextFloat() * 39));
        label.setForeground(new Color(rand.nextInt()));
        tmpPanel.add(label);
    }
    if (tagCloudPanel == null) {
        tagCloudPanel = new JScrollPane(tmpPanel, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
                JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    } else {
        jPanel3.remove(tagCloudPanel);
        jPanel3.validate();
        tagCloudPanel = new JScrollPane(tmpPanel, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
                JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    }
    //tagCloudPanel.setLayout(new ScrollPaneLayout());
    //tagCloudPanel.setAutoscrolls(true);
    tmpPanel.validate();
    tagCloudPanel.validate();
    jPanel3.add(tagCloudPanel, BorderLayout.CENTER);
    jPanel3.validate();

}

From source file:edu.ucla.stat.SOCR.applications.demo.PortfolioApplication2.java

private void setSliders() {
    if (sliderPanel != null)
        sliderPanel.removeAll();//from w  ww.  ja va 2 s.c om
    else
        sliderPanel = new JPanel();

    JPanel rPanel = new JPanel();
    // rPanel.setBackground(Color.blue);
    JPanel rPanel2 = new JPanel();
    // rPanel2.setBackground(Color.green);
    rPanel.setAlignmentX(LEFT_ALIGNMENT);
    rPanel2.setAlignmentX(LEFT_ALIGNMENT);

    rSliders = new FloatTextField[numStocks]; //expected return

    JPanel matrixPanel = new JPanel();
    matrixPanel.setAlignmentX(LEFT_ALIGNMENT);
    mSliders = new FloatTextField[15];

    JPanel tPanel = new JPanel();
    tPanel.setAlignmentX(LEFT_ALIGNMENT);
    //   tPanel.setBackground(Color.blue);

    //tSlider = new ValueSliderFloat2("Tangency:", -0.5, 0.5, false);
    tSlider = new FloatTextField("Tangency:", t1_y, 0, 1);
    //tSlider.setPreferredSize(new Dimension(SLIDER_SIZE_X,45));

    newMSlider(1, 0, tSlider, tPanel);

    //expected return
    rPanel.setLayout(new GridBagLayout());
    rPanel.add(new JLabel("Expected Return:"));
    for (int i = 0; i < numStocks; i++) {
        rSliders[i] = new FloatTextField("E(R" + (i + 1) + ")", ExpectedReturn[i][0], -0.2, 0.2);
        rSliders[i].setPreferredSize(new Dimension(SLIDER_SIZE_X / numStocks, 45));
        rSliders[i].setToolTipText("Adjusting the value of expected return for stock " + (i + 1) + ".");
        newMSlider(1, i, rSliders[i], rPanel);
    }

    ER_matrix = new Matrix(numStocks, 1, ExpectedReturn);

    // Covariance
    rPanel2.setLayout(new GridBagLayout());
    rPanel2.add(new JLabel("Variance:"));
    for (int i = 0; i < numStocks; i++) {
        mSliders[i] = new FloatTextField("VAR(R" + (i + 1) + ")", COVR[i][i], 0.0, 0.2);
        mSliders[i].setPreferredSize(new Dimension(SLIDER_SIZE_X / numStocks, 45));
        mSliders[i].setToolTipText("Adjusting the value of variance " + (i + 1) + ".");
        newMSlider(1, i, mSliders[i], rPanel2);
    }

    matrixPanel.setLayout(new GridBagLayout());

    if (covarianceFlag)
        addRadioButton(0, 0, "Switch Input Matrix:", "Switch Input Matrix", switchArray, 0, matrixPanel,
                (ActionListener) this);
    else
        addRadioButton(0, 0, "Switch Input Matrix:", "Switch Input Matrix", switchArray, 1, matrixPanel,
                (ActionListener) this);
    switchedFlag = false;

    if (covarianceFlag) {
        // matrixPanel.add(new JLabel("Covariance Matrix:"));

        int k = numStocks;
        for (int i = 1; i < numStocks; i++)
            for (int j = 0; j < i; j++) {
                mSliders[k] = new FloatTextField("COV" + (i + 1) + (j + 1), COVR[i][j], -0.5, 0.5);
                mSliders[k].setPreferredSize(new Dimension(SLIDER_SIZE_X / numStocks, 45));
                mSliders[k]
                        .setToolTipText("Adjusting the value of correlation " + (i + 1) + "," + (j + 1) + ".");
                newMSlider(i, j, mSliders[k], matrixPanel);

                k++;
            }
    } else {
        //   matrixPanel.add(new JLabel("Correlation Matrix:"));
        int k = numStocks;
        for (int i = 1; i < numStocks; i++)
            for (int j = 0; j < i; j++) {
                mSliders[k] = new FloatTextField("CORR" + (i + 1) + (j + 1), CORR[i][j], -0.5, 0.5);
                mSliders[k].setPreferredSize(new Dimension(SLIDER_SIZE_X / numStocks, 45));
                mSliders[k]
                        .setToolTipText("Adjusting the value of correlation " + (i + 1) + "," + (j + 1) + ".");
                newMSlider(i, j, mSliders[k], matrixPanel);
                if (CORR[i][j] > 1)
                    System.out.println("setting slider CORR[" + i + "][" + j + "]=" + CORR[i][j]);

                k++;
            }
    }

    try {
        CORR = covr2corr(COVR, ExpectedReturn, numStocks);
    } catch (Exception e) {
        System.out.println("corrlation out of range.");
    }

    covr_matrix = new Matrix(numStocks, numStocks, COVR);
    corr_matrix = new Matrix(numStocks, numStocks, CORR);

    sliderPanel.setLayout(new BoxLayout(sliderPanel, BoxLayout.PAGE_AXIS));
    /*Box box = Box.createVerticalBox();
    box.add(rPanel);
    box.add(rPanel2);
    box.add(new JLabel("Correlation Matrix:"));
    box.add(matrixPanel);
    sliderPanel.add(box);*/
    //sliderPanel.setBackground(Color.red);
    matrixPanel.validate();
    sliderPanel.add(rPanel);
    sliderPanel.add(rPanel2);
    sliderPanel.add(Box.createRigidArea(new Dimension(0, 5)));
    sliderPanel.add(matrixPanel);
    sliderPanel.add(tPanel);
    sliderPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    sliderPanel.validate();
    //sliderPanel.setBackground(Color.white);
}

From source file:app.RunApp.java

/**
 * Create metrics table for multiple datasets tab
 * //from w  ww . ja  v  a2 s .  c o m
 * @param table Table of metrics
 * @param jpanel Panel
 * @param rowData Cell values
 * @param posx Position X
 * @param posy Position Y
 * @param width Width
 * @param height Height
 */
public void createJTableMetricsMultipleDatasets(JTable table, JPanel jpanel, Object rowData[][], int posx,
        int posy, int width, int height) {
    TableModel model = new MetricsTableModel(rowData, "multi");

    table.setModel(model);

    TableColumnModel tcm = table.getColumnModel();

    tcm.getColumn(0).setPreferredWidth(320);

    tcm.getColumn(1).setPreferredWidth(40);
    tcm.getColumn(1).setMaxWidth(40);
    tcm.getColumn(1).setMinWidth(40);

    JScrollPane scrollPane = new JScrollPane(table);

    scrollPane.setBounds(posx, posy, width, height);

    table.setBorder(BorderFactory.createLineBorder(Color.black));

    jpanel.add(scrollPane, BorderLayout.CENTER);
    jpanel.repaint();
    jpanel.validate();
}

From source file:app.RunApp.java

/**
 * Create graph/*www .  j  ava  2  s.c  om*/
 * 
 * @param jpanel Panel
 * @return ChartPanel with the generated graph
 */
private ChartPanel createGraph(JPanel jpanel) {
    XYDataset xydataset = new DefaultXYDataset();
    JFreeChart chart = ChartFactory.createXYLineChart("Box diagram", "Values", "", xydataset,
            PlotOrientation.VERTICAL, false, true, false);

    XYPlot xyplot = (XYPlot) chart.getPlot();
    xyplot.setBackgroundPaint(Color.white);
    xyplot.setDomainGridlinePaint(Color.gray);
    xyplot.setRangeGridlinePaint(Color.gray);

    //Hide Y axis
    xyplot.getRangeAxis().setTickLabelsVisible(false);

    ChartPanel cp1 = new ChartPanel(chart);
    cp1.setSize(new Dimension(450, 300));
    cp1.setBounds(260, 100, 450, 300);
    cp1.setPreferredSize(new Dimension(450, 300));
    cp1.repaint();

    jpanel.setBounds(260, 100, 450, 300);
    jpanel.setLayout(new BorderLayout());
    jpanel.add(cp1, BorderLayout.CENTER);
    jpanel.repaint();
    jpanel.validate();

    return cp1;
}