将对象放在另一个网格布局之上

时间:2022-06-19 07:57:18

Using GridbagLayout, I am trying to orient a text area under a JFreeChart Chart. However, when I try to do so the two objects are placed side by side instead. Here is how I am approaching the problem:

使用GridbagLayout,我试图在JFreeChart图表下定位文本区域。但是,当我尝试这样做时,两个对象并排放在一起。以下是我处理这个问题的方式:

    //Set Gridbag constraints for chart
     GridBagLayout  gridbag3 = new GridBagLayout();

     GridBagConstraints c3 = new GridBagConstraints();      
     c3.anchor = GridBagConstraints.NORTH;

     GridBagConstraints c3a = new GridBagConstraints();
     c3a.anchor = GridBagConstraints.SOUTH;


     gridbag3.setConstraints(chartPanel3,c3);
     gridbag3.setConstraints(scrollPane,c3a);

     tab3.setLayout(gridbag3);
     tab3.add(chartPanel3);
     tab3.add(scrollPane);

The dimensions of the objects were defined as:

对象的尺寸定义为:

    chartPanel3.setPreferredSize(new Dimension(800, 600));


    final JTextArea errorLog = new JTextArea("Error Log:");
    errorLog.setPreferredSize(new Dimension(300,100));
    JScrollPane scrollPane = new JScrollPane(errorLog);
    scrollPane.setBounds(10,60,780,500);

The view that I'm seeing is the following: 将对象放在另一个网格布局之上

我看到的观点如下:

How can I go about placing this graph on top of this text area?

我怎样才能把这个图形放在这个文本区域的顶部呢?

2 个解决方案

#1


0  

You need to set your constraints: specifically set gridy so the scrollpane is placed in a row below the chart.

您需要设置约束:具体地设置gridy,以便scrollpane被放置在图表下面的一行中。

#2


0  

Have you tried using WindowBuilder for Eclipse. It is really good with this type of stuff.

您是否尝试过使用WindowBuilder进行Eclipse。这种东西真的很好。

#1


0  

You need to set your constraints: specifically set gridy so the scrollpane is placed in a row below the chart.

您需要设置约束:具体地设置gridy,以便scrollpane被放置在图表下面的一行中。

#2


0  

Have you tried using WindowBuilder for Eclipse. It is really good with this type of stuff.

您是否尝试过使用WindowBuilder进行Eclipse。这种东西真的很好。