JTextPane
動的に行われた選択に対応して追加し、JComboBox
それらを上下に並べたいと思います。ここで私は使用しSpringLayout
ました。他のレイアウトが適している場合は、それを手伝ってください。私は以下のように試しました:
コード
package com.vastu;
import java.awt.Color;
public class Panel1 extends JPanel {
/**
*
*/
private static final long serialVersionUID = 1L;
public Panel1() {
setuppanel();
}
@SuppressWarnings("unchecked")
private void setuppanel(){
setBackground(new Color(147, 112, 219));
final SpringLayout springLayout = new SpringLayout();
setLayout(springLayout);
JLabel lblTarabala = new JLabel("TARABALA :");
springLayout.putConstraint(SpringLayout.NORTH, lblTarabala, 11, SpringLayout.NORTH, this);
springLayout.putConstraint(SpringLayout.WEST, lblTarabala, 36, SpringLayout.WEST, this);
lblTarabala.setFont(new Font("Times New Roman", Font.BOLD, 18));
add(lblTarabala);
final JTextPane txtrNakshatrastarOfYajamana = new JTextPane();
springLayout.putConstraint(SpringLayout.NORTH, txtrNakshatrastarOfYajamana, 50, SpringLayout.NORTH, this);
springLayout.putConstraint(SpringLayout.WEST, txtrNakshatrastarOfYajamana, 36, SpringLayout.WEST, this);
txtrNakshatrastarOfYajamana.setFont(new Font("Times New Roman", Font.BOLD, 14));
txtrNakshatrastarOfYajamana.setEditable(false);
txtrNakshatrastarOfYajamana.setBackground(new Color(147, 112, 219));
txtrNakshatrastarOfYajamana.setText("STAR OF THE OWNER :");
add(txtrNakshatrastarOfYajamana);
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"};
@SuppressWarnings({ "rawtypes" })
JComboBox star = new JComboBox(nakshatras);
springLayout.putConstraint(SpringLayout.NORTH, star, 50, SpringLayout.NORTH, this);
springLayout.putConstraint(SpringLayout.WEST, star, 210, SpringLayout.WEST, this);
star.setBackground(new Color(211, 211, 211));
add(star);
String[] more={"MORE MEMBERS","FATHER","MOTHER","HUSBAND","WIFE","SON","DAUGHTER"};
@SuppressWarnings("rawtypes")
JComboBox members = new JComboBox(more);
springLayout.putConstraint(SpringLayout.NORTH, members, 50, SpringLayout.NORTH, this);
springLayout.putConstraint(SpringLayout.WEST, members, 382, SpringLayout.WEST, this);
add(members);
members.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
@SuppressWarnings("rawtypes")
JComboBox jc = (JComboBox) e.getSource();
Integer i=jc.getSelectedIndex();
if(i==0){
repaint();
}else if(i==1){
JTextPane newmember=new JTextPane();
newmember.setFont(new Font("Times New Roman", Font.BOLD, 14));
newmember.setEditable(false);
newmember.setText("STAR OF FATHER :");
newmember.setBackground(new Color(147, 112, 219));
springLayout.putConstraint(SpringLayout.SOUTH, newmember, 35, SpringLayout.SOUTH, txtrNakshatrastarOfYajamana);
springLayout.getLayoutAlignmentX(txtrNakshatrastarOfYajamana);
add(newmember);
revalidate();
}
}
});
}
}
レイアウト画像
「STAR OF FATHER」が「STAR OF OWNER」ペインのすぐ下に表示されるようにします。誰でも解決策を提案できますか?