2

To make things easier, I've created a figure below of what I want:

enter image description here

Basically, the panel on the left displays an image and the panel on the right will display a colorbar. I've already got two panel classes that display the image and colorbar how I want, but now I want to put them side by side inside a JFrame. Now, I'm not exactly sure what the best implementation would be for this so if anyone has any conceptually different ideas then they would be appreciated.

I've already tried a GridLayout, but it seemed to position things in terms of percentages. The one tricky thing about this is that I'd like the panel on the right to be a fixed width because I don't want the colorbar to change widths as the frame is resized.

JustinBlaber
  • 4,629
  • 2
  • 36
  • 57

1 Answers1

0

Ok, well JB Nizet answered it pretty easily, but here is the code I used:

public class Data2DFrame extends JFrame{
    public Data2DFrame(Data2D data2D,double min,double max,Data2DColorMap data2DColorMap) {    
        // Set image if data is nonempty
        if (data2D.height > 0 && data2D.width > 0) {
            // Set data panel
            Data2DPanel data2DPanel = new Data2DPanel(data2D,min,max,data2DColorMap);
            data2DPanel.toggleKeyBoard(); // Allow keyboard interaction
            data2DPanel.toggleMouse();    // Allow mouse interaction
            // data2DPanel.setPreferredSize(new Dimension(data2D.width,data2D.height));

            // Set colorbar
            Data2DColorBar data2DColorBar = new Data2DColorBar(min,max,data2DColorMap);
            // data2DColorBar.setPreferredSize(new Dimension(100,data2D.height));

            // Arrange
            this.setLayout(new BorderLayout());
            this.add(data2DPanel,BorderLayout.CENTER);
            this.add(data2DColorBar,BorderLayout.LINE_END);
            this.pack();
        }        
    }
}

enter image description here

JustinBlaber
  • 4,629
  • 2
  • 36
  • 57