我试图将 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)
我得到的屏幕是这样的:
此外,奇怪的是,当我调整屏幕大小时,我看到了这个:
好像整个图表都大幅缩小了...有什么想法可以解决这个问题吗?提前非常感谢
最佳答案
您可以使用这个frame.setResizable(false);
关于java - GridBagLayout - 图表和标签的放置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16460168/