我正在尝试将 JfreeChart 和一些标签放在 gridBagLayout 上。我希望图表位于右侧,水平和垂直占据框架的所有空间,并跨越框架宽度的 90%。标签应该在相同大小的单元格中,位于左侧图表,每个占宽度的 10% 和高度的 33%。到目前为止,代码如下所示:
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)
我得到的屏幕是这样的:
此外,奇怪的是,当我调整屏幕大小时,我看到了这个:
好像整个图表都大大缩小了......有什么想法可以解决这个问题吗?非常感谢提前