Ich möchte euch erstmal meinen Code zeigen:
Das Problem habe ich rot makiert. Wenn ich diese Zeile weglasse, wird alles so angezeigt wie ich das gerne haben würde. Versuche ich jedoch setText von der Area zu machen, dann ist auf einmal alles weg!! Es wird nur noch der Jframe angezeigt und sonst gar nichts!
Es kommt leider keine Fehlermeldung oder sonstiges... kann mir einer bitte helfen?
EDIT:!!!
Ich korrigiere.. es ist scheinbar egal ob die Zeile drin ist oder nicht.. manchmal funktionierts.. manchmal nicht.. wtf? Weiß einer wieso dieser kauderwelsch geschieht?
Java:
import javax.swing.*;
import java.awt.*;
public class Gui{
public static void main (String args[]) {
Gui application = new Gui();
application.init();
}
public void addComponent(Container cont, GridBagLayout gbl, Component c, int x, int y,
int width, int height, double weightx, double weighty) {
GridBagConstraints gbc = new GridBagConstraints();
gbc.fill = GridBagConstraints.BOTH;
gbc.gridx = x; gbc.gridy = y;
gbc.gridwidth = width; gbc.gridheight = height;
gbc.weightx = weightx; gbc.weighty = weighty;
gbl.setConstraints( c, gbc );
cont.add( c );
}
public void init() {
JFrame mainframe = new JFrame("Name");
GridBagLayout gbl = new GridBagLayout();
GridBagConstraints gbc = new GridBagConstraints();
gbc.fill = GridBagConstraints.BOTH;
mainframe.setLayout(gbl);
mainframe.setSize(800, 600);
mainframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mainframe.setVisible(true);
JRadioButton rbV = new JRadioButton( "Vorspeise" );
JRadioButton rbH = new JRadioButton( "Hauptgericht" );
JRadioButton rbD = new JRadioButton( "Dessert" );
ButtonGroup g = new ButtonGroup();
g.add(rbV); g.add(rbH); g.add(rbD);
JPanel menuAuswahl = new JPanel();
menuAuswahl.add(rbV); menuAuswahl.add(rbH); menuAuswahl.add(rbD);
JTextArea gerichte = new JTextArea();
StringBuffer buffer = new StringBuffer();
buffer.append("asdjkasjkd");
buffer.append("asdhjkadwbnekjqbnjebnqjwkebnjkqwebn");
[COLOR="Red"]gerichte.setText(buffer.toString());[/COLOR]
// x y w h wx wy
addComponent( mainframe, gbl, menuAuswahl, 0, 0, 3, 2, 1.0, 0.02 );
addComponent( mainframe, gbl, new JButton("2"), 3, 0, 1, 4, 0.3 , 0 );
addComponent( mainframe, gbl, gerichte, 0, 3, 3, 1, 0 , 1.0 );
addComponent( mainframe, gbl, new JButton("5"), 0, 4, 3, 1, 0 , 0.02 );
addComponent( mainframe, gbl, new JButton("6"), 3, 4, 1, 1, 0 , 0 );
}
Das Problem habe ich rot makiert. Wenn ich diese Zeile weglasse, wird alles so angezeigt wie ich das gerne haben würde. Versuche ich jedoch setText von der Area zu machen, dann ist auf einmal alles weg!! Es wird nur noch der Jframe angezeigt und sonst gar nichts!
Es kommt leider keine Fehlermeldung oder sonstiges... kann mir einer bitte helfen?
EDIT:!!!
Ich korrigiere.. es ist scheinbar egal ob die Zeile drin ist oder nicht.. manchmal funktionierts.. manchmal nicht.. wtf? Weiß einer wieso dieser kauderwelsch geschieht?