jlabel을 동적으로 추가하려면 jlabel을 동적으로 추가하고 싶습니다. jlabel을 추가하기 위해 사용할 레이아웃을 파악할 수 없습니다. 여기에 난 상자 레이아웃을 사용하지만 필드는 전체 화면에 표시되는 모든 힌트 또는 솔루션이jbutton에서 jlabel을 다른 것 아래에 추가하는 방법
코드가 여기
package com.vastu;
import javax.swing.JPanel;
public class spanel extends JPanel {
String[] nakshatras = {"SELECT","Ashwini","Bharani","Kritika","Rohini","Mrugashira","Aardra","Punarvasu","Pushya","Aashlesha","Magha","Poorva","Phalguni","Uttara","Phalguni","Hasta","Chitra","Swati","Vishakha","Anuradha","Jyeshta","Moola","Poorvashada","Uttarashada","Shravana","Dhanishta","Shatabhisha","Poorvabhadra","Uttarabhadra","Revati"};
String[] more={"MORE MEMBERS","FATHER","MOTHER","HUSBAND","WIFE","SON","DAUGHTER"};
public spanel() {
setBackground(new Color(147, 112, 219));
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
JLabel lblTarabala = new JLabel("tarabala:");
add(lblTarabala);
JLabel lblStarOfOwner = new JLabel("STAR OF OWNER :");
add(lblStarOfOwner);
JComboBox comboBox = new JComboBox(nakshatras);
add(comboBox);
JComboBox comboBox_1 = new JComboBox(more);
add(comboBox_1);
comboBox_1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
JComboBox jc = (JComboBox) e.getSource();
Integer i=jc.getSelectedIndex();
if(i==0){
repaint();
}else if(i==1){
JLabel newmember=new JLabel();
JComboBox star_f=new JComboBox(nakshatras);
GridBagConstraints gbc_starf = new GridBagConstraints();
star_f.setBackground(new Color(211, 211, 211));
newmember.setFont(new Font("Times New Roman", Font.BOLD, 14));
newmember.setText("STAR OF FATHER :");
newmember.setBackground(new Color(147, 112, 219));
gbc_starf.gridwidth=5;
add(newmember);
add(star_f);
revalidate();
}else if(i==2){
JLabel newmember=new JLabel();
JComboBox star_m=new JComboBox(nakshatras);
GridBagConstraints gbc_starm = new GridBagConstraints();
star_m.setBackground(new Color(211, 211, 211));
newmember.setFont(new Font("Times New Roman", Font.BOLD, 14));
newmember.setText("STAR OF MOTHER :");
newmember.setBackground(new Color(147, 112, 219));
gbc_starm.gridwidth=5;
add(newmember);
add(star_m);
revalidate();
}else if(i==3){
JLabel newmember=new JLabel();
JComboBox star_h=new JComboBox(nakshatras);
GridBagConstraints gbc_starh = new GridBagConstraints();
star_h.setBackground(new Color(211, 211, 211));
newmember.setFont(new Font("Times New Roman", Font.BOLD, 14));
newmember.setText("STAR OF HUSBAND :");
newmember.setBackground(new Color(147, 112, 219));
gbc_starh.gridwidth=5;
add(newmember);
add(star_h);
revalidate();
}
}
});
}
}
간다 이해할 수있을 것이다.
방법으로 내가 정의 BoxLayout가에 구성 요소의 크기를 조정 하죠?
'당신'BoxLayout'를 사용할 수 있지만 당신은 당신이 무엇을 시도했다 몇 가지 코드를 제공해야 호출'재 검증()'와 repaint' 당신은'VerticalLayout를 구성 요소를 추가, 이후 '만약 당신이'swingx'을 사용한다면 – nachokk