我试图将一个JfreeChart与一些标签一起放在gridBagLayout上。我希望图表位于右侧,横向和纵向占据框架的所有空间,并且跨越框架宽度的90%。标签应该位于相同大小的单元格中,在左侧图表,每个占10%和33%的高度。到目前为止,代码如下所示:GridBagLayout - 放置图表和标签
val chartPanel = new ChartPanel(chart, true, true, true, true, true)
//layout
setLayout(new GridBagLayout())
val c = new GridBagConstraints()
//natural height, maximum width
c.fill = GridBagConstraints.BOTH
c.gridx = 1
c.gridy = 0
c.weightx = 0.9
add(chartPanel, c)
val label = new JLabel("Count: ")
val c2 = new GridBagConstraints()
c2.fill = GridBagConstraints.VERTICAL
c2.gridx = 0
c2.gridy = 0
c2.weightx = 0.1
add(label, c2)
val label2 = new JLabel("Count2: ")
val c3 = new GridBagConstraints()
c3.fill = GridBagConstraints.VERTICAL
c3.gridx = 0
c3.gridy = 1
c3.weightx = 0.1
add(label2, c3)
val label3 = new JLabel("Count3: ")
val c4 = new GridBagConstraints()
c4.fill = GridBagConstraints.VERTICAL
c4.gridx = 0
c4.gridy = 2
c4.weightx = 0.1
add(label3, c4)
和我收到的画面是这样的:
此外,bizzarly,当我调整屏幕,我看到的是:
就好像整个图表大大缩小......任何想法如何解决这个问题?非常感谢
_val chartPanel _...这是Scala吗? – Reimeus 2013-05-09 11:03:58
是的,使用从斯卡拉应用 – user221218 2013-05-09 11:08:13