noob braucht unterstützung

Status
Nicht offen für weitere Antworten.
K

klink

Gast
hi,

schreibe zum ersten mal mit swing rum und versuche grad mal n fenster anzeigen zu lassen.
hab den code aus mehreren quellen zusammengeschnippelt und leider funktionierts nicht. er zeigt es mir nicht an.

aufruf:
Code:
		public void actionPerformed(ActionEvent e)
		{
			testWindow test= new testWindow();
			test.isVisible();
		}


class:
Code:
import java.awt.Component;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;



public class TestWindow extends JFrame {

	public TestWindow()
	{	
    	this.setLayout(new GridBagLayout()); 
        addComponentInLayout(getContentPanel(), 
    		    0, 0, 1, 1, 
                0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0,0,0,0)); 
        addComponentInLayout(createContents(), 
        		0, 1, 1, 1, 
                1.0, 1.0, GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, new Insets(0,0,0,0)); 
        
    } 

    private JPanel getContentPanel() { 
    	JPanel contentPanel = new JPanel(); 
        contentPanel.setLayout(new FlowLayout()); 
        
        JLabel welcomeLabel = new JLabel("Konfiguration"); 
        welcomeLabel.setFont(new java.awt.Font("MS Sans Serif", Font.BOLD, 11));
        contentPanel.add(welcomeLabel); 
        
        return contentPanel; 
   } 
		
	private JPanel createContents() {
		
		
		JPanel panel = new JPanel();
		JLabel configurationText = new JLabel("Pfad");
		JTextField path = new JTextField("/.");
        
	       panel.setLayout(new GridBagLayout());
	        
	       addComponentInContainer(panel,configurationText, 
	       	    0, 0, 1, 1, 
	       	    1.0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(30,0,0,0));
	  
	       addComponentInContainer(panel, path, 
	    	    0, 1, 1, 1,
	    	    1.0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0,0,0,0));
	           
	       
	       setBounds(400, 250, 200, 200);
	       return panel;
	   } 
	    
	     //Fügt eine Componenten in das GridbagLayout ein 

	    public void addComponentInLayout(Component aComp, int gridX, int gridY, int gridWidth, int gridHeight, double weightX, 
	    		double weightY, int anchor, int fill, Insets insets) { 
	       GridBagConstraints theConstraints = new GridBagConstraints(gridX, gridY, gridWidth, gridHeight, weightX, 
	    		   weightY, anchor, fill, insets, 0, 0); 

	       add(aComp, theConstraints); 
	    } 
	     
	     // Fügt eine Componenten in ein z.B. Panel ein. 
	   
	    public void addComponentInContainer(JComponent aPanel,Component aComp, int gridX, int gridY, int gridWidth, int gridHeight, double weightX, 
	            double weightY, int anchor, int fill, Insets insets) { 
	       GridBagConstraints theConstraints = new GridBagConstraints(gridX, gridY, gridWidth, gridHeight, weightX, 
	             weightY, anchor, fill, insets, 0, 0); 
	       aPanel.add(aComp, theConstraints); 
	    }   
}

erkennt jemand warum er mir das nicht anzeigt?
 

diggaa1984

Top Contributor
wie wärs mit:

Code:
public class Foo {

    public static void main(String[] args) {
        testWindow test= new testWindow(); 
        test.setVisible(true);
    }
}
 
Status
Nicht offen für weitere Antworten.

Ähnliche Java Themen

Neue Themen


Oben