[英]Trying to add 2 (JLabel, JSlider) TO A Panel with BorderLayout, only JSlider gets drawn
I have copy my code to display a text feild and a JSlider) from a project that usses a JFrame 我从一个使用JFrame的项目中复制我的代码以显示文本字段和JSlider
My new project usses a JInternalFrame, and only the slider is drawn. 我的新项目使用JInternalFrame,只绘制滑块。 If I comment out the code it will draw the text field, seems like it only wonts to draw 1 control. 如果我注释掉代码它会绘制文本字段,看起来它只能绘制1个控件。
code 码
JPanel containerPanel = new JPanel(new BorderLayout() );
cDrawComponent mDrawComponent = new cDrawComponent();
containerPanel.add(mDrawComponent,BorderLayout.CENTER);
JLabel mJLabel=new JLabel("000");
mJSlider = new JSlider(JSlider.HORIZONTAL, 0, 1000,500);
JPanel sliderPanel = new JPanel(new BorderLayout() );
// TRYING TO ADD 2 CONPOMENTS ONLY SLIDER IS SHOWN sliderPanel.add(mJLabel); //试图仅添加2个对象SLIDER是如何显示sliderPanel.add(mJLabel); sliderPanel.add(mJSlider); sliderPanel.add(mJSlider); containerPanel.add(sliderPanel,BorderLayout.SOUTH); containerPanel.add(sliderPanel,BorderLayout.SOUTH);
class SliderListener implements ChangeListener {
public void stateChanged(ChangeEvent e) {
JSlider source = (JSlider) e.getSource();
ted++;
if (!source.getValueIsAdjusting()) {
{
sliderPes = (int) source.getValue();
int max=source.getMaximum();
scrollPes=max-sliderPes;
repaint();
}
}
}
}
mJSlider.addChangeListener(new SliderListener());
add(containerPanel);
Use 采用
sliderPanel.add(mJLabel, BorderLayout.WEST);
The BorderLayout can show only one component at the center (Default, if ommited). BorderLayout只能在中心显示一个组件(默认,如果省略)。 That's usually the last one, that got added. 这通常是最后一个,增加了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.