When you create your ChartPanel
, you have several options that affect the result:
-
Accept the
DEFAULT_WIDTH
andDEFAULT_HEIGHT
: 680 x 420. -
Specify the preferred
width
andheight
in the constructor. -
Invoke
setPreferredSize()
explicitly if appropriate. -
Override
getPreferredSize()
to calculate the size dynamically.@Override public Dimension getPreferredSize() { // given some values of w & h return new Dimension(w, h); }
-
Choose the layout of the container to which the
ChartPanel
will be added. Note that the default layout ofJPanel
isFlowLayout
, while that ofJFrame
isBorderLayout
. As a concrete example,ThermometerDemo
uses both preferred values in the constructor and aGridLayout
for the container to allow dynamic resizing.