0

I am making a Java GUI application, wherein a JPanel displays a HeatMap using the HeatMap Java class. When a user right clicks on this JPanel, a popup menu is displayed. Within this, the first option is to View the zoomed heatmap in a separate window. On clicking this option a new window should open providing a bigger image of the actual HeatMap. I am using the following code to perform this:

 JOptionPane.showMessageDialog(new GUIMain(), getPanel(), "Zoomed heat map", JOptionPane.PLAIN_MESSAGE);

getPanel() is a method that returns a panel containing the heatmap.

private JPanel getPanel() {
        JPanel zoomedImagePanel = new JPanel();
        zoomedImagePanel.add(getHeatMap());
        zoomedImagePanel.repaint();
        zoomedImagePanel.revalidate();
        return zoomedImagePanel;
    }

With the above code, I get a very small HeatMap in a new window and the HeatMap from the main JPanel disappears completely. Is using JOptionPane the wrong way to display the zoomed image? Also, not sure why the HeatMap from the main JPanel in the parent window disappears.

novicegeek
  • 765
  • 2
  • 9
  • 26
  • 2
    You can't add the same component to multiple panels http://stackoverflow.com/questions/4620601/cant-a-swing-component-be-added-to-multiple-containers that is probably why the `HeatMap` disappears from the main `JPanel`. – Titus Oct 07 '16 at 10:57
  • What is `HeatMap`? It's not a standard class of Java (at least I cannot find it in SDK). Please provide a [SSCCE](http://sscce.org), so we can reproduce your problem. – Sergiy Medvynskyy Oct 07 '16 at 10:57
  • @SergiyMedvynskyy I am using the `HeatMap` class by https://www.mbeckler.org/heatMap/ – novicegeek Oct 07 '16 at 11:19
  • @Titus I read the post. I think it is applicable to Swing components and not objects like `HeatMap`. Please correct me if wrong. I my current code I am adding the same 'HeatMap` object in two different JPanels. – novicegeek Oct 07 '16 at 11:22
  • 1
    @novicegeek If you can do this `zoomedImagePanel.add(getHeatMap());` it means that the `HeatMap` class extends the `Component` class. – Titus Oct 07 '16 at 11:24

0 Answers0