Hallo,
ich habe versucht ein JComboBox Feld in ein JPane zu setzen. doch jeder Versuch endet damit das das JPane mehr oder weniger ausgefüllt wird. kann man das irgendwie umgehen oder mach ich nur was falsch?
hier mal der Code:
Ich weis das es nicht so schön formatiert ist, aber das ist ja auch erst mal ein Versuch.
Es dreht sich eigentlich nur um folgendes Stück Code:
[JAVA=42-68]public Inventur04(String titel){
super(titel);
setDefaultCloseOperation(EXIT_ON_CLOSE);
JPanel cp=new JPanel();
comBox1.addItem("test1");
comBox1.addItem("test2");
add(cp);
GridBagLayout gl=new GridBagLayout();
GridBagConstraints gbc = new GridBagConstraints();
//setLayout(cp.getLayout());
gbc.gridx = 3;
gbc.gridy = 0;
gbc.gridwidth = 0;
gbc.gridheight = 0;
gbc.weightx = 10;
gbc.weighty = 10;
gbc.fill = GridBagConstraints.BOTH;
gl.setConstraints(comBox1, gbc);
cp.setLayout(gl);
cp.setBackground(Color.lightGray);
cp.add(new JButton("Speichern"));
cp.add(new JTextField(20));
cp.add(comBox1);
}[/code]
MfG Fritz
ich habe versucht ein JComboBox Feld in ein JPane zu setzen. doch jeder Versuch endet damit das das JPane mehr oder weniger ausgefüllt wird. kann man das irgendwie umgehen oder mach ich nur was falsch?
hier mal der Code:
Java:
import java.awt.Choice;
import java.awt.Color;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.event.CaretEvent;
import javax.swing.event.CaretListener;
public class Inventur04 extends JFrame
implements ActionListener, CaretListener{
/**
*
*/
private static final long serialVersionUID = 1L;
JTabbedPane tp;
Choice comBox1=new Choice();
JLabel label1;
JTextArea textFeld1;
// Konstruktor
/**
* @param titel
*/
/**
* @param titel
*/
/**
* @param titel
*/
public Inventur04(String titel){
super(titel);
setDefaultCloseOperation(EXIT_ON_CLOSE);
JPanel cp=new JPanel();
comBox1.addItem("test1");
comBox1.addItem("test2");
add(cp);
GridBagLayout gl=new GridBagLayout();
GridBagConstraints gbc = new GridBagConstraints();
//setLayout(cp.getLayout());
gbc.gridx = 3;
gbc.gridy = 0;
gbc.gridwidth = 0;
gbc.gridheight = 0;
gbc.weightx = 10;
gbc.weighty = 10;
gbc.fill = GridBagConstraints.BOTH;
gl.setConstraints(comBox1, gbc);
cp.setLayout(gl);
cp.setBackground(Color.lightGray);
cp.add(new JButton("Speichern"));
cp.add(new JTextField(20));
cp.add(comBox1);
}
public static void main(String[] args) {
Inventur04 fenster=new Inventur04("TITEL");
fenster.setLocation(100,100);
fenster.setSize(640,400);
fenster.setVisible(true);
}
@Override
public void caretUpdate(CaretEvent e) {
// TODO Auto-generated method stub
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
}
}
Es dreht sich eigentlich nur um folgendes Stück Code:
[JAVA=42-68]public Inventur04(String titel){
super(titel);
setDefaultCloseOperation(EXIT_ON_CLOSE);
JPanel cp=new JPanel();
comBox1.addItem("test1");
comBox1.addItem("test2");
add(cp);
GridBagLayout gl=new GridBagLayout();
GridBagConstraints gbc = new GridBagConstraints();
//setLayout(cp.getLayout());
gbc.gridx = 3;
gbc.gridy = 0;
gbc.gridwidth = 0;
gbc.gridheight = 0;
gbc.weightx = 10;
gbc.weighty = 10;
gbc.fill = GridBagConstraints.BOTH;
gl.setConstraints(comBox1, gbc);
cp.setLayout(gl);
cp.setBackground(Color.lightGray);
cp.add(new JButton("Speichern"));
cp.add(new JTextField(20));
cp.add(comBox1);
}[/code]
MfG Fritz