Example usage for javax.swing JPanel setVisible

List of usage examples for javax.swing JPanel setVisible

Introduction

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

Prototype

@BeanProperty(hidden = true, visualUpdate = true)
public void setVisible(boolean aFlag) 

Source Link

Document

Makes the component visible or invisible.

Usage

From source file:MainClass.java

public static void main(String[] args) {
    JFrame f = new JFrame();

    final JPanel p1 = new JPanel();
    p1.add(new JLabel("GlassPane Example"));
    JButton show = new JButton("Show");
    p1.add(show);/*w ww  .ja  v a 2  s  . c o m*/
    p1.add(new JButton("No-op"));
    f.getContentPane().add(p1);

    final JPanel glass = (JPanel) f.getGlassPane();

    glass.setVisible(true);
    glass.setLayout(new GridBagLayout());
    JButton glassButton = new JButton("Hide");
    glass.add(glassButton);

    f.setSize(150, 80);
    f.setVisible(true);

    show.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            glass.setVisible(true);
            p1.repaint();
        }
    });
    glassButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            glass.setVisible(false);
            p1.repaint();
        }
    });
}

From source file:GlassExample.java

/** Construct a Splash screen with the given image */
public static void main(String[] args) {
    JFrame f = new JFrame("GlassPane");

    final JPanel p1 = new JPanel();
    p1.add(new JLabel("GlassPane Example"));
    JButton show = new JButton("Show");
    p1.add(show);//from   w w w  .  j  av  a2  s.  c om
    p1.add(new JButton("No-op"));
    f.getContentPane().add(p1);

    final JPanel glass = (JPanel) f.getGlassPane();

    glass.setVisible(true);
    glass.setLayout(new GridBagLayout());
    JButton glassButton = new JButton("Hide");
    glass.add(glassButton);

    f.setSize(150, 80);
    f.setVisible(true);

    boolean debug = false;
    if (debug) {
        System.out.println("Button is " + glassButton);
        System.out.println("GlassPane is " + glass);
    }

    // Add actions to the buttons...

    // show button (re-)shows the glass pane.
    show.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            glass.setVisible(true);
            p1.repaint();
        }
    });
    // hide button hides the Glass Pane to show what's under.
    glassButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            glass.setVisible(false);
            p1.repaint();
        }
    });
}

From source file:probe.com.model.util.vaadintoimageutil.HeatmapSwingComponent.java

public String generateHeatmap(String[] rows, String[] columns, String[][] data) {

    JPanel heatmapPanelLayout = new JPanel();
    heatmapPanelLayout.setLayout(null);/*from w  w  w .j a  v  a  2 s  . c om*/
    heatmapPanelLayout.setVisible(true);
    heatmapPanelLayout.setBorder(new LineBorder(Color.BLACK));
    int width = (columns.length + 1) * 50;
    int height = (rows.length + 1) * 50;
    heatmapPanelLayout.setSize(width, height);
    JPanel cornerCell = initCell("#ffffff", 0, 0);
    int x = 50;
    int y = 0;
    heatmapPanelLayout.add(cornerCell);

    for (String headerCell : columns) {
        JPanel cell = initCell(headerCell, x, y);
        x += 50;
        heatmapPanelLayout.add(cell);

    }
    y = 50;
    for (String headerCell : rows) {
        JPanel cell = initCell(headerCell, 0, y);
        y += 50;
        heatmapPanelLayout.add(cell);

    }
    x = 50;
    y = 50;
    for (String[] row : data) {
        for (String color : row) {
            JPanel cell = initCell(color, x, y);
            heatmapPanelLayout.add(cell);
            x += 50;
        }
        x = 50;
        y += 50;
    }

    BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    Graphics2D graphics = image.createGraphics();
    graphics.setPaint(Color.WHITE);
    heatmapPanelLayout.paint(graphics);
    //        super.paint(graphics);
    byte[] imageData = null;

    try {

        ImageEncoder in = ImageEncoderFactory.newInstance(ImageFormat.PNG, new Float(0.084666f));
        imageData = in.encode(image);
    } catch (Exception e) {
        System.out.println(e.getLocalizedMessage());
    }

    String base64 = Base64.encodeBytes(imageData);
    base64 = "data:image/png;base64," + base64;
    return base64;
    //
    //        JFrame frame = new JFrame();
    //        frame.setSize(1000, 1000);
    //        frame.add(heatmapPanelLayout);
    //        frame.setVisible(true);

    //        return "";
}

From source file:probe.com.view.body.quantdatasetsoverview.diseasegroupsfilters.heatmap.HeatMapImgGenerator.java

public String generateHeatmap(String[] rows, String[] columns, String[][] data) {

    JPanel heatmapPanelLayout = new JPanel();
    heatmapPanelLayout.setLayout(null);//from   w  ww  . j  a  v a  2 s  .c  om
    heatmapPanelLayout.setVisible(true);

    int width = (columns.length + 1) * 50;
    int height = (rows.length + 1) * 50;
    heatmapPanelLayout.setSize(width, height);
    JPanel cornerCell = initCell("#ffffff", 0, 0);
    int x = 50;
    int y = 0;
    heatmapPanelLayout.add(cornerCell);

    for (String headerCell : columns) {
        JPanel cell = initCell(headerCell, x, y);
        x += 50;
        heatmapPanelLayout.add(cell);

    }
    y = 50;
    for (String headerCell : rows) {
        JPanel cell = initCell(headerCell, 0, y);
        y += 50;
        heatmapPanelLayout.add(cell);

    }
    x = 50;
    y = 50;
    for (String[] row : data) {
        for (String color : row) {
            JPanel cell = initCell(color, x, y);
            heatmapPanelLayout.add(cell);
            x += 50;
        }
        x = 50;
        y += 50;
    }

    BufferedImage image = new BufferedImage(width + 10, height + 10, BufferedImage.TYPE_INT_ARGB);
    Graphics2D graphics = image.createGraphics();
    graphics.setPaint(Color.WHITE);
    graphics.setBackground(Color.WHITE);
    heatmapPanelLayout.paint(graphics);
    byte[] imageData = null;

    try {

        ImageEncoder in = ImageEncoderFactory.newInstance(ImageFormat.PNG, new Float(0.084666f));
        imageData = in.encode(image);
    } catch (Exception e) {
        System.out.println(e.getLocalizedMessage());
    }

    String base64 = Base64.encodeBytes(imageData);
    base64 = "data:image/png;base64," + base64;
    return base64;

}

From source file:ANNFileDetect.GraphingClass.java

public void drawchartFromInt(Integer[] values) throws IOException {
    DefaultCategoryDataset ds = new DefaultCategoryDataset();
    for (int i = 0; i < values.length; i++) {
        //double a = (double) i;
        ds.addValue(i, String.valueOf(i), String.valueOf(values[i]));
        //ds.addValue((double)i, "Times", values[i]);
    }/*from   www  .  j  a v  a 2s .  c o m*/
    JFreeChart chart = ChartFactory.createBarChart("chart", "quantity", "value", ds, PlotOrientation.VERTICAL,
            true, true, false);
    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setSize(1200, 700);
    JPanel jf = new JPanel();
    jf.setSize(1300, 800);
    chartPanel.setVisible(true);
    chartPanel.setZoomAroundAnchor(true);
    chartPanel.setDomainZoomable(true);
    jf.add(chartPanel);
    JLabel jl = new JLabel("hello!");
    jf.add(jl);
    jf.setVisible(true);
    jf.repaint();
    //jf.setAlwaysOnTop(true);
}

From source file:front.TestTable.java

private void agregarHistograma() {
    // Tenemos que convertir los numeros generados a un vector de double.
    double[] valoresGeneradosEnDouble = obtenerValoresEnDouble();
    Histograma histograma = new Histograma("Frecuencias del generador", valoresGeneradosEnDouble,
            cantIntervalos);/* w  w w .ja  v a  2 s  .c o  m*/
    JPanel histoPanel = histograma.obtenerPanel();
    histoPanel.setVisible(true);
    panelHistograma.add(histoPanel);
    panelHistograma.validate();
}

From source file:udpserver.UDPui.java

/**
 * Creates new form UDPui/*from ww w. j a  v  a  2  s . com*/
 */
public UDPui() {
    // <editor-fold defaultstate="collapsed" desc="Graph">
    series = new XYSeries("ECG Reading");
    series.setMaximumItemCount(50);
    XYSeriesCollection dataset = new XYSeriesCollection(series);
    JFreeChart chart = ChartFactory.createXYLineChart("ECG Reading", "Time (seconds)", "Voltage (volt)",
            dataset);

    final XYPlot plot = chart.getXYPlot();
    NumberAxis domain = (NumberAxis) plot.getDomainAxis();

    JPanel jPanel1 = new JPanel();
    jPanel1.setLayout(new java.awt.BorderLayout());
    jPanel1.setVisible(true);
    jPanel1.setSize(600, 500);
    jPanel1.add(new ChartPanel(chart), BorderLayout.CENTER);
    jPanel1.validate();
    add(jPanel1);
    // </editor-fold>
    initComponents();
    receiveUDP();
    //        tempReceiveUDP();
    //        new UDPServer(valuePane);
}

From source file:gui.images.CodebookVectorProfilePanel.java

/**
 * Sets the data to be shown./*from w  w w .  j a v a 2 s.co  m*/
 *
 * @param occurrenceProfile Double array that is the neighbor occurrence
 * profile of this visual word.
 * @param codebookIndex Integer that is the index of this visual word.
 * @param classColors Color[] of class colors.
 * @param classNames String[] of class names.
 */
public void setResults(double[] occurrenceProfile, int codebookIndex, Color[] classColors,
        String[] classNames) {
    int numClasses = Math.min(classNames.length, occurrenceProfile.length);
    this.codebookIndex = codebookIndex;
    this.occurrenceProfile = occurrenceProfile;
    DefaultPieDataset pieData = new DefaultPieDataset();
    for (int cIndex = 0; cIndex < numClasses; cIndex++) {
        pieData.setValue(classNames[cIndex], occurrenceProfile[cIndex]);
    }
    JFreeChart chart = ChartFactory.createPieChart3D("codebook vect " + codebookIndex, pieData, true, true,
            false);
    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setDirection(Rotation.CLOCKWISE);
    plot.setForegroundAlpha(0.5f);
    PieRenderer prend = new PieRenderer(classColors);
    prend.setColor(plot, pieData);
    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new Dimension(140, 140));
    chartPanel.setVisible(true);
    chartPanel.revalidate();
    chartPanel.repaint();
    JPanel jp = new JPanel();
    jp.setPreferredSize(new Dimension(140, 140));
    jp.setMinimumSize(new Dimension(140, 140));
    jp.setMaximumSize(new Dimension(140, 140));
    jp.setSize(new Dimension(140, 140));
    jp.setLayout(new FlowLayout());
    jp.add(chartPanel);
    jp.setVisible(true);
    jp.validate();
    jp.repaint();

    JFrame frame = new JFrame();
    frame.setBackground(Color.WHITE);
    frame.setUndecorated(true);
    frame.getContentPane().add(jp);
    frame.pack();
    BufferedImage bi = new BufferedImage(jp.getWidth(), jp.getHeight(), BufferedImage.TYPE_INT_ARGB);
    Graphics2D graphics = bi.createGraphics();
    jp.print(graphics);
    graphics.dispose();
    frame.dispose();
    imPanel.removeAll();
    imPanel.setImage(bi);
    imPanel.setVisible(true);
    imPanel.revalidate();
    imPanel.repaint();
}

From source file:agentlogfileanalyzer.histogram.AbstractHistogram.java

/**
 * Creates a panel for error messages. The error message is given as
 * parameter./*  w w w  .ja va  2  s  . c  o  m*/
 * 
 * @param _text
 *            the error message
 * @return a panel for error messages
 */
private JPanel createErrorPanel(String _text) {

    JPanel jPanelChart = new JPanel();
    // ...display error notice instead of chart.
    JTextArea jTextAreaAnzeige = new JTextArea(_text);
    jTextAreaAnzeige.setVisible(true);
    jTextAreaAnzeige.setBackground(new Color(238, 238, 238));
    jPanelChart.add(jTextAreaAnzeige);
    jPanelChart.setVisible(true);
    return jPanelChart;
}

From source file:fusion.Fusion.java

private static void initListPanel() {

    final JPanel listPanel = new JPanel();
    listPanel.setVisible(true);

    // Buttons/*from w  ww.  j av a 2 s .  c  o m*/
    JButton setSameAsLinksFile = new JButton("Set SameAsLinks file");
    JButton setDatasetFile1 = new JButton("Set Dataset1 file");
    JButton setDatasetFile2 = new JButton("Set Dataset2 file");

    JButton sourceButton = new JButton(" Edit Source Information ");
    JButton rulesButton = new JButton("        Edit Logic Rules         ");

    JLabel homogeneityLabel = new JLabel("Threshold for Homogeneity");
    final JTextField homogeneityTextfield = new JTextField("0.10");
    JLabel frequencyLabel = new JLabel("Threshold for Occurence Frequency");
    final JTextField frequencyTextfield = new JTextField("0.01");

    homogeneityTextfield.setInputVerifier(new MyInputVerifier());
    frequencyTextfield.setInputVerifier(new MyInputVerifier());

    JButton constructINAButton = new JButton("     Construct INA graph     ");
    JButton constructButton = new JButton("Generic construct graph");
    JButton loadButton = new JButton("   Load previous graph   ");
    JButton fusionButton = new JButton("           Data fusion            ");

    JButton displayFusionButton = new JButton("     Display fused data     ");

    setSameAsLinksFile.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            try {
                setSameAsLinksFile();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    });

    setDatasetFile1.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            try {
                setDatasetFile1();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    });
    setDatasetFile2.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            try {
                setDatasetFile2();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    });

    sourceButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            try {
                java.awt.Desktop.getDesktop().open(new File(sourceInfoFile));
            } catch (IOException ex) {
                Logger.getLogger(Fusion.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    });

    rulesButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            try {
                java.awt.Desktop.getDesktop().open(new File(logicRulesFile));
            } catch (IOException ex) {
                Logger.getLogger(Fusion.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    });

    constructINAButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {

            if (homogeneityTextfield.getText().length() != 0 && frequencyTextfield.getText().length() != 0) {

                Fusion.homogeneityThreshold = Float.parseFloat(homogeneityTextfield.getText());
                Fusion.occurenceFrequencyThreshold = Float.parseFloat(frequencyTextfield.getText());
                try {

                    constructINAGraph();
                    //genericConstructGraph("", "", "", "", "", "", "");

                } catch (FileNotFoundException ex) {
                    Logger.getLogger(Fusion.class.getName()).log(Level.SEVERE, null, ex);
                } catch (IOException ex) {
                    Logger.getLogger(Fusion.class.getName()).log(Level.SEVERE, null, ex);
                } catch (URISyntaxException e) {
                    e.printStackTrace();
                }
            } else {
                JOptionPane.showMessageDialog(guiFrame, "Please fill in all the fields!");
            }

        }
    });

    loadButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            loadGraph();
        }
    });

    fusionButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            executeFusion();
        }
    });

    constructButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {

            try {
                genericConstructGraph();
            } catch (IOException | AlignmentException | URISyntaxException e) {
                e.printStackTrace();
            }

        }
    });

    displayFusionButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            displayFusedGraph();
        }
    });

    listPanel.setLayout(new GridBagLayout());

    GridBagConstraints c = new GridBagConstraints();

    c.gridx = 0;
    c.gridy = 0;
    listPanel.add(setSameAsLinksFile, c);
    c.gridx = 1;
    c.gridy = 0;
    listPanel.add(setDatasetFile1, c);
    c.gridx = 2;
    c.gridy = 0;
    listPanel.add(setDatasetFile2, c);
    c.gridx = 1;
    c.gridy = 1;
    listPanel.add(sourceButton, c);
    c.gridx = 1;
    c.gridy = 2;
    listPanel.add(rulesButton, c);
    c.gridx = 1;
    c.gridy = 3;
    listPanel.add(homogeneityLabel, c);
    c.gridx = 2;
    c.gridy = 4;
    listPanel.add(homogeneityTextfield, c);
    c.gridx = 1;
    c.gridy = 4;
    listPanel.add(frequencyLabel, c);
    c.gridx = 2;
    c.gridy = 5;
    listPanel.add(frequencyTextfield, c);
    c.gridx = 1;
    c.gridy = 5;
    listPanel.add(constructINAButton, c);
    c.gridx = 1;
    c.gridy = 6;
    listPanel.add(constructButton, c);
    c.gridx = 1;
    c.gridy = 7;
    listPanel.add(loadButton, c);
    c.gridx = 1;
    c.gridy = 8;
    listPanel.add(fusionButton, c);
    c.gridx = 1;
    c.gridy = 9;
    listPanel.add(displayFusionButton, c);

    //container.add(listPanel, BorderLayout.WEST);
    split.add(listPanel);
    guiFrame.setVisible(true);
}