텍스트를 JLabel로 설정할 수 없습니다.이 코드는 구문 오류 ("{"제외)를 표시하지만 다른 점은 잘못된 것 같습니다.JComboBOX에서 항목을 선택하면
public class CircleController extends JPanel {
private JComboBox product1=new JComboBox(Application.listArray);
private JLabel jlb1=new JLabel();
//..........some fields more
// constructor....
public CircleController() {
// Panel to group labels
JPanel panel1 = new JPanel();
//..........some labels....
//another panel
JPanel panel2 = new JPanel();
panel2.setLayout(new GridLayout(4,4,20,20));
panel2.add(product1);
panel2.add(jlb1);
및 에러 코드의 일부
//product1 is combobox, jlbt is label wich I want to set when I selected item from combobox
product1.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) { // in this line shows me an error
(Product name:Application.manu) {
if ((String)product1.getSelectedItem()==name.getName()){
String price1=Double.toString(name.getPrice());
jlb1.setText(price1);
}
}
if (model != null){
model.setProduct((String)product1.getSelectedItem());}}
});
프로그램은 내가이 문을 추가 할 때
product1.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
if (model != null){
model.setProduct((String)product1.getSelectedItem());}}
});
는하지만,이 코드를 잘 작동 (이 문이 선택되어 있고이 좋은)
(Product name:Application.manu) {
if ((String)product1.getSelectedItem()==name.getName()){
String price1=Double.toString(name.getPrice());
jlb1.setText(price1);
}
}
within product1.addItemListener(new ItemListener() {....
프로그램 오류
레이블을 설정하려면 ItemListener
을 추가해야합니까?
: //sscce.org/), short, runnable, compilable, 단지'JFrame','JComboBox','JLabel' – mKorbel