comboBoxのデータの右づめ表示
GridBagLayoutでデーターの右づめ表示が出来ません。
Q1)下記のコードで、変更方法をお教えください。
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.LineBorder;
public class comboBox_Right extends JFrame {
public static JComboBox[] combo=new JComboBox[4];
static comboBox_Right frame;
public static void main(String args[]){
frame=new comboBox_Right("AAAA");
frame.setVisible(true);
}
comboBox_Right(String title) {
setTitle(title);
setBounds(100, 100, 300, 200);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel p = new JPanel();
//===========================
GridBagLayout layout=new GridBagLayout();
GridBagConstraints gbc=new GridBagConstraints();
p.setBackground(Color.GREEN); //GRREN-->BLUE back ground color of West panel
p.setLayout(layout); //これが効いた <--- layout=new GridBagLayout();
LineBorder border = new LineBorder(Color.BLACK, 1, true);
//ComboBox data
String[][] combodata = { {"A0", "B0", "C0", "D0"}, //No.1 Combo
{"A1", "B1", "C1", "D1"}, //No.1 Combo
{"A2", "B2", "C2", "D2"}, //No.1 Combo
{"A3", "B3", "C3", "D3"}, //No.1 Combo
};
int wx=100, wy=25;
for(int i=0; i<4; i++){
combo[i] = new JComboBox(combodata[i]); //make 4 comboBox
((JLabel)combo[i].getRenderer()).setHorizontalAlignment(JLabel.RIGHT);
setComboBox(combo[i], layout, gbc, 0, i, wx, wy); //0:index
}
for(int i=0; i<4; i++) p.add(combo[i]); //add 4 comboBox
Container contentPane = getContentPane();
contentPane.add(p, BorderLayout.CENTER);
}
void setComboBox( JComboBox combo, GridBagLayout layout, GridBagConstraints gbc, int px, int py, int wx, int wy){
combo.setEditable(true);
GCombo_Layout(layout, combo, gbc, px, py, wx, wy);
}
void GCombo_Layout(GridBagLayout layout, JComboBox combo, GridBagConstraints gbc, int x, int y, int wx, int wy){
combo.setPreferredSize(new Dimension(wx,wy));
gbc.gridx = x;
gbc.gridy = y;
gbc.gridheight = 1;
gbc.weightx = 1.0d;
gbc.weighty = 1.0d;
gbc.fill = GridBagConstraints.NONE;
gbc.insets = new Insets(0, 0, 0, 0);
layout.setConstraints(combo, gbc);
}
}
//以上
お礼
shylock さま 出来ました。 本当に有難うございます。 この件で、やく半日以上調べましたが、出来ませんでした。 以上