由於某種原因Jlist
不會顯示在我的小程序。Jlist沒有顯示/出現在小程序
它顯示在滑塊的右側,但只有當您單擊各個元素時才顯示。
我試過this.validate()
和this.repaint()
沒有運氣。誰能幫我嗎?
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JApplet;
import java.awt.Graphics;
import javax.swing.JList;
import javax.swing.JRadioButton;
import javax.swing.JSlider;
import javax.swing.ListSelectionModel;
public class HeatingHome extends JApplet implements ActionListener
{
// declare variables here
JRadioButton switchIt = new JRadioButton();
JSlider tempControl = new JSlider(JSlider.VERTICAL, 10, 15, 11);
String[] theRooms = {"Porch", "Kitchen", "Living Room", "Hall", "Bedroom 1", "Bathroom", "Bedroom 2"};
JList roomsList = new JList(theRooms);
public void init()
{
setSize(1000,600);
}
public void paint(Graphics g)
{
super.paint(g);
roomsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
roomsList.setBounds(700, 200, 150, 150);
roomsList.setVisible(true);
roomsList.setEnabled(true);
add(roomsList);
//tempControl.addChangeListener(e);
tempControl.setMajorTickSpacing(10);
tempControl.setPaintLabels(true);
tempControl.setMinorTickSpacing(1);
tempControl.setPaintTicks(true);
tempControl.setBounds(600, 200, 100, 200);
tempControl.setEnabled(true);
add(tempControl);
}
@Override
public void actionPerformed(ActionEvent e) {
throw new UnsupportedOperationException("Not supported yet.");
}
}