怕你们看不见这里 这里把它贴出来。 JTextArea text = new JTextArea(10,20); int x = btnTextParser.getX(); int y = btnTextParser.getY(); text.setBounds(btnTextParser.getX(), btnTextParser.getY() + 10, upPanel.getWidth(), 50); <span style="color: rgb(255, 0, 0);">//这个地方我怎么都设置不了它的位置 不知道是什么原因?我想要让文本域放到按钮下面</span> upPanel.add(text);
layout manager在布局的时候怎么觉得组件的大小呢? 使用组件的 preferred size 决定其大小所以设置左边的 preferred size就可以了 public void setPreferredSize(Dimension preferredSize) Sets the preferred size of this component to a constant value. Subsequent calls to getPreferredSize will always return this value. Setting the preferred size to null restores the default behavior. Parameters: preferredSize - The new preferred size, or null
JTextArea text = new JTextArea(10,20);
int x = btnTextParser.getX();
int y = btnTextParser.getY();
text.setBounds(btnTextParser.getX(), btnTextParser.getY() + 10, upPanel.getWidth(), 50); <span style="color: rgb(255, 0, 0);">//这个地方我怎么都设置不了它的位置 不知道是什么原因?我想要让文本域放到按钮下面</span>
upPanel.add(text);
使用组件的 preferred size 决定其大小所以设置左边的 preferred size就可以了
public void setPreferredSize(Dimension preferredSize)
Sets the preferred size of this component to a constant value. Subsequent calls to getPreferredSize will always return this value. Setting the preferred size to null restores the default behavior.
Parameters:
preferredSize - The new preferred size, or null