[JAVA]Gridlayout macht Probs
Hi Leute ....
Hab fast das gleiche schon im Gulliboard gepostet nur iwie keine gute Antwort erhalten vlt. könnte ihr mir ja helfen hier der COde:
PHP-Code:
//My Multi Umrechner //by Thoran.eu / CT 55 neocrom package mUr ; import javax . swing . JFrame ; import java . awt . Color ; import javax . swing . UIManager ; import javax . swing . UnsupportedLookAndFeelException ; import java . awt . Font ; import java . awt . Container ; import java . awt . BorderLayout ; import javax . swing . JLabel ; import javax . swing . JPanel ; import javax . swing . JTextField ; import java . awt . GridLayout ; import javax . swing . JComboBox ; import javax . swing . JButton ; import java . awt . FlowLayout ; import javax . swing . border . LineBorder ; import java . awt . event . ActionListener ; import java . awt . event . ActionEvent ; public class Mf extends JFrame implements ActionListener { //Attribute private Font cour , fat ; private Container cp ; private JLabel heaTxt , in1Txt , in2Txt , txt3 , outTxt1 , outTxt2 , in2HeadTxt , in2VsTxt , in2EinTxt ; private JPanel inPan , outPan , inPan2 ; private JTextField userIn ; private JComboBox einheit1 , vorsilbe ; private JButton change ; private LineBorder outBor ; private GridLayout inLay , in2Lay ; private FlowLayout outLay ; //Methoden //Konstruktor public Mf () { super ( "My Multi-umrechner" ); setResizable ( false ); this . setDefaultCloseOperation ( JFrame . EXIT_ON_CLOSE ); cour = new Font ( "Phetsarath OT" , Font . PLAIN , 14 ); fat = new Font ( "Phetsarath OT" , Font . BOLD , 16 ); cp = this . getContentPane (); cp . setFont ( cour ); cp . setForeground ( Color . WHITE ); cp . setBackground ( Color . BLACK ); cp . setLayout (new BorderLayout ()); //////////////////////////////////////////// ////////////HEAD STYLE BEREICH:////////////// ////////////////////////////////////////////// heaTxt =new JLabel ( "Changer by CT55/Thoran.eu - neocrom" ); heaTxt . setForeground ( Color . WHITE ); cp . add ( heaTxt , BorderLayout . NORTH ); //Hinzufügen der Componente zum CP ///////////////////////////////////////////////////// //////////////////////////////////////////// ////////////INPUT1 BEREICH:////////////// ////////////////////////////////////////////// inLay =new GridLayout ( 3 , 2 ); inLay . setVgap ( 4 ); inPan =new JPanel ( inLay ); inPan . setBorder (new LineBorder ( Color . WHITE )); inPan . setForeground ( Color . WHITE ); inPan . setBackground ( Color . BLACK ); //inPan.setBorder(); in1Txt =new JLabel ( "Umzuwandelnde Größe:" ); in1Txt . setForeground ( Color . WHITE ); inPan . add ( in1Txt ); userIn =new JTextField ( 2 ); userIn . setFont ( cour ); userIn . setAutoscrolls ( true ); inPan . add ( userIn ); txt3 =new JLabel ( "Vorsilbe:" ); txt3 . setForeground ( Color . WHITE ); inPan . add ( txt3 ); String [] inVorsilbe ={ "[T]erra (*10^12)" , "[G]iga (*10^9)" , "[M]ega (*10^6)" , "[K]ilo (*10^3)" , "[D]ezi (*10^2)" , "[C]enti (*10^1)" , "\" \"(*10^0)" , "[m]ili (*10^-3" , "[u]Mikro (*10^-6)" , "[n]ano (*10^-9)" , "[p]iko (*10^-12)" }; vorsilbe =new JComboBox ( inVorsilbe ); inPan . add ( vorsilbe ); in2Txt =new JLabel ( "Einheit:" ); in2Txt . setForeground ( Color . WHITE ); inPan . add ( in2Txt ); String [] inEinheit1 = { "[m]eter" , "[i]nch" , "[C]elsius" , "[Fa]hrenheit" , "[K]elvin" , "A[n]zahl" , "[D]utzend" , "[B]yte" , "[Bi]t" , "[F]arrad" , "[U]Volt" , "[I]Ampere" , "[R]Wiederstand" , "Zei[t]" }; einheit1 = new JComboBox ( inEinheit1 ); inPan . add ( einheit1 ); cp . add ( inPan , BorderLayout . WEST ); ///////////////////////////////////////////// //////////////////////////////////////////// ////////////INPUT2 BEREICH:////////////// ////////////////////////////////////////////// in2Lay =new GridLayout ( 2 , 2 ); in2Lay . setVgap ( 4 ); inPan2 =new JPanel ( in2Lay ); inPan2 . setBackground ( Color . BLACK ); inPan2 . setForeground ( Color . WHITE ); inPan2 . setBorder (new LineBorder ( Color . WHITE )); in2HeadTxt =new JLabel ( "Umwandeln in: " ); in2HeadTxt . setForeground ( Color . WHITE ); inPan2 . add ( in2HeadTxt ); in2EinTxt =new JLabel ( "Einheit:" ); in2EinTxt . setForeground ( Color . WHITE ); inPan2 . add ( in2EinTxt ); in2VsTxt =new JLabel ( "Vorsilbe:" ); in2VsTxt . setForeground ( Color . WHITE ); inPan2 . add ( in2VsTxt ); cp . add ( inPan2 , BorderLayout . EAST ); /////////////////////////////////////////////// //////////////////////////////////////////// ////////////RECHEN BEREICH:////////////// ////////////////////////////////////////////// outLay =new FlowLayout ( 2 ); outLay . setAlignment ( FlowLayout . CENTER ); outLay . setVgap ( 4 ); outPan =new JPanel ( outLay ); outPan . setBackground ( Color . darkGray ); outBor =new LineBorder ( Color . WHITE ); outPan . setBorder ( outBor ); change =new JButton ( "->Change<-" ); change . addActionListener ( new ActionListener (){ public void actionPerformed (final ActionEvent e ) { outTxt2 . setText ( " " + rechnung ()); }}); outPan . add ( change ); outTxt1 =new JLabel ( "Ergebniss:" ); outTxt1 . setForeground ( Color . RED ); outTxt2 =new JLabel ( "" ); outTxt2 . setForeground ( Color . WHITE ); outTxt2 . setFont ( fat ); //outTxt.setBorder(new LineBorder(Color.GREEN)); outPan . add ( outTxt1 ); outPan . add ( outTxt2 ); cp . add ( outPan , BorderLayout . SOUTH ); ///////////////////////////////////////////// pack (); } public static void main ( String [] args ) { try { UIManager . setLookAndFeel ( UIManager . getCrossPlatformLookAndFeelClassName ()); } catch ( UnsupportedLookAndFeelException e ) { System . out . println ( "An Error during init function of Frame:" + e ); } catch ( ClassNotFoundException e ) { System . out . println ( "An Error during init function of Frame:" + e ); } catch ( InstantiationException e ) { System . out . println ( "An Error during init function of Frame:" + e ); } catch ( IllegalAccessException e ) { System . out . println ( "An Error during init function of Frame:" + e ); } Mf mine =new Mf (); mine . setVisible ( true ); } public double rechnung () { return 2 ; } public void actionPerformed (final ActionEvent e ){} }
soweit zum Code ... jetzt zu meinem Problem:
Also .... der Container im East bereich des Borderlayout (inp2) bereich hat Gridlayout und wurde mit (2,2) initalisiert .... sprich 2 Zeilen a 2 Spalten. Leider beim hinzufügen von den Componenten addet er aber immer nur 1 Component pro Zeile
???? *ratlos* hflt. kann mir jmd helfen
mfg neo