Netbeans eigene Componenten einfügen

Status
Nicht offen für weitere Antworten.

Mammon

Mitglied
Möchte bei einer Desktop Anwendung in Netbeans eine eigene Componente hinzufügen. Habs derzeit einfach den Layout geändert und dann hinzugefügt was wiederum das ganze Layout des Programms verändert.
Kann ich im Design Manager ihm direkt eine eigene Componente hinzfügen?
 
G

Gast

Gast
Ja das geht. Hab jetzt zwar kein Netbeans da, aber soweit ich weiss kann man die Komponentenleiste rechts anpassen (einfach mal rechtsklicken und gucken was da so gibt). Man kann dann das Jar auswählen in dem sich die Komponente befindet und dann die benötigte Klasse auswählen. Anschließende kann man die Komponente wie in Matisse üblich per Drag&drop platzieren.
 

Mammon

Mitglied
Ich hab mir eine eigene Javabean erstellt und konnte diese auch hinzufügen aber wenn ich diese in ein Frame einfügen möchte bekomm ich Fehlermeldung das es kein gülitiges Javabean ist.
 

L-ectron-X

Gesperrter Benutzer
Um eine beliebige selbst erstellte Komponente in die Palette einzufügen, klickst du mit der rechten Maustaste in der Ansicht Projects auf die entsprechende Komponente im Projekt-Baum.
Daraufhin öffnet sich ein Kontextmenü, an dessen Ende sich der Eintrag Tools findet. Weiter geht's über Add to Palette... und den Auswahldialog, in welchem du eine passende Kategorie auswählst.
Danach erscheint deine Komponente in der Palette unter der von dir ausgewählten Kategorie und kann per Matisse (GUI-Designer) in deine GUIs eingebaut werden.
Es ist dabei völlig unerheblich, ob du die Komponente mit Matisse zusammengeklickt, oder selbst im Code-Editor geschrieben hast.

Wie hast du es gemacht?
 

Mammon

Mitglied
Ja genau so hab ich es gemacht
Muss die Komponente irgendwas bestimmtes noch implementieren? Ich hab sie von JComponent abgeleitet und paintComponent Methode überschrieben.
 

Mammon

Mitglied
Wenn ich es in ein Frame reinziehe bekomm ich die Meldung
The component connot be instantiated. Please make sure it is a JavaBeans component.

Hier der Code:

Code:
public class BarChart extends JComponent implements Serializable
{
	
	int width;
	int height;
	String chartName;
	String chartMark;
	Calculation calc;
	
	float temp=0;
	float []array;
	
	float heightdia;
	float widthdia;
	float x0p;
	float y0p;
	float spacex;
	float spacey;
	float balkwidth;
	float spacenumbx;
	float spacenumby;

    public BarChart()
    {



    }
	
	
	public BarChart(int width,int height,String chartName,String chartMark,Calculation calc)
	{
		this.chartName=chartName;
		this.chartMark=chartMark;
		this.width=width;
		this.height=height;	
		this.calc=calc;
		
		
		heightdia=(height-(height/10));					// H�he des Diagramms
		widthdia=(width-(width/10));					// Breite des Diagramms
		x0p=((width/10));								// x des Nullpunktes
		y0p=(heightdia);								// y des Nullpunktes
		spacex=widthdia/10;								// Abstand der Zahlen auf der x Achse
		spacey=heightdia/11;							// Abstand der Prozente auf der y Achse
		balkwidth=widthdia/15;							// Breite des Balkens
		spacenumbx=((height/20));						// Abstand der Zahlen zur x Achse
		spacenumby=((width/12)); 						// Abstand der Zahlen zur y Achse
		
		
		array=calc.getBarHeight(chartName,chartMark);					// Balkenh�he berrechnen
		
		for(int i=0;i<9;i++)
		{
			array[i]=array[i]*(spacey/10);									// Umrechnen der H�he von % in Pixel , (spacey/10)entspricht der H�he von 1 Prozent
		}
				
	}

    @Override
	public void paintComponent(Graphics g)
	{	
		
		Font font = new Font("Serif",Font.PLAIN,10);
		g.setFont(font);
		g.setColor(Color.black);
		//y Achse zeichnen
		g.drawLine((int)x0p,(int)y0p,(int)x0p,(int)(y0p-heightdia));
		//x Achse zeichnen
		g.drawLine((int)x0p,(int)y0p,(int)(x0p+widthdia),(int)y0p);
		
		// Zahlen zeichnen unter der x Achse
	/*	for(int i=1;i<=9;i++)
		{
			g.drawString(Integer.toString(i),(int)(x0p+(spacex*i)),(int)(y0p+spacenumbx));
		}*/
		// Prozente zeichnen neberen der y Achse
		for(int i=10;i<=100;i=i+10)
		{
			g.drawString(Integer.toString(i)+"%",(int)(x0p-spacenumby),(int)(y0p-(spacey*(i/10))));
			g.drawLine((int)(x0p-5),(int)(y0p-(spacey*(i/10))),(int)(x0p+5),(int)(y0p-(spacey*(i/10))));
			
		}
		
		for(int i=0;i<9;i++)
		{
			
			// Farbe wechseln f�r die eigenen Zahlen
			if(chartName.equals("Einsteiger"))
			{
				if(calc.userData.einst==i+1)
				{
					g.setColor(Color.red);
				}
			}
			if(chartName.equals("Rückrat"))
			{
				if(calc.userData.rück==i+1)
				{
					g.setColor(Color.red);
				}
			} 
			if(chartName.equals("Aussteiger"))
			{
				if(calc.userData.ausst==i+1)
				{
					g.setColor(Color.red);
				}
			} 
			if(chartName.equals("Mischfeld1"))
			{
				if(calc.userData.misch1==i+1)
				{
					g.setColor(Color.red);
				}
			} 
			if(chartName.equals("Mischfeld2"))
			{
				if(calc.userData.misch2==i+1)
				{
					g.setColor(Color.red);
				}
			} 
			if(chartName.equals("Carrot"))
			{
				if(calc.userData.carrot==i+1)
				{
					g.setColor(Color.red);
				}
			}  
			g.drawString(Integer.toString(i+1),(int)(x0p+(spacex*(i+1))),(int)(y0p+spacenumbx));								// Zahlen zeichnen unter der x Achse			
			g.drawRect((int)((x0p+(spacex*(i+1)))-balkwidth/2),(int)(y0p)-(int)(array[i]),(int)balkwidth,(int)array[i]);		// Balken zeichnen
			g.setColor(Color.black);
		}
		
	}
}
 

Mammon

Mitglied
so habs jetzt hinbekommen
kann jetzt meine eigenen Componenten einfügen
Jetzt hab ich das Problem das ich keine eigenen Properties setzen kann wie zB. die Größe
Hab mir das Turtorial ein wenig angesehen und wird das über Bean Pattern und dann Add|Property gemacht.
Leider weis ich nicht wie ich wie zu nem Bean Pattern komme. Es sollte normal bei den Files unter der Klasse aufscheinen.
 
Status
Nicht offen für weitere Antworten.
Ähnliche Java Themen
  Titel Forum Antworten Datum
G eigene Library In NetBeans 11.1 IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 4
M Eigene Jar-Dateien zu Netbeans-Projekt hinzufügen? IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 7
C NetBeans - eigene Komponenten in Palette einbinden IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 2
N NetBeans IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 3
M Netbeans nutzt veraltete Bibliotheken für JAX-WS IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 2
W Debugger - Netbeans vs. VSCode IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 4
J Erstellen eines java Projekts mit Gradel in netbeans. IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 12
R Ist netbeans noch eine gute Wahl? IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 1
mihe7 NetBeans 17 IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 2
MiMa Netbeans zu IntelliJ mit Maven konvertieren IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 14
I NetBeans 15 - Strg+Z (undo) und Strg+Y (redo) funzen nicht mehr nach Start der Java-Anwendung IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 8
J Netbeans 14 friert unter Linus Mint 21 prötzlich ein IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 8
mihe7 NetBeans NetBeans 16 ist da IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 0
M Altes Java Projekt in Netbeans importieren IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 3
MiMa Methoden in Netbeans vergleichen? IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 23
M Linux Mint - Apache NetBeans 14 - Installationsanleitung deutsch IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 4
Neumi5694 Netbeans Warnung IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 3
T NetBeans NetBeans IDE 13 | Cannot find main class IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 8
J Seltsames Verhalten einer Klasse in netbeans IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 6
S License-Header in NetBeans 8.2 IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 2
G Netbeans 12.6 IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 9
kodela NetBeans App lässt sich ausßerhalb von NetBeans nicht ausführen IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 6
J Netbeans - WakaTime - Plugin sendet keine Daten IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 5
J Netbeans - Werte von Variablen überwachen IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 6
donnico2 Fehler beim Installieren von Apache Netbeans IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 4
J netbeans - refactoring funktioniert nicht mehr IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 3
S Netbeans unterstützung für "Rule Switch" - Bug? IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 8
O NetBeans Netbeans 12.0 - Hintergrundfarbe, auch im Navigator und Projekt umstellen IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 2
J Kombinationsproblem: netbeans, gradle, mysql, json IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 5
O NetBeans Netbeans 8.2 mit JKD 15 ? IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 4
J Seltsames Verhalten von netbeans bezüglich fxml Dateien IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 4
J netbeans 12 - wie -Xlint:deprecation aktivieren IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 3
J Netbeans 11.1 - Gradel aktualisieren IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 6
E Suche aktuelle Netbeans-Version für Win 10 IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 30
B Netbeans: Java Script Libraries funktioniert nicht IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 6
J NetBeans Projekt erstellen nicht möglich IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 1
J Bekomme keine lauffähige jar (netbeans/gradle) IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 12
J Install JasperReports on netbeans/gradle Projekt IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 5
W NetBeans Umzug von Netbeans 8.2 -> Netbeans 11.1: Plug-Ins IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 7
F Umstieg von Netbeans 8 mit JDK 8 auf Apache Netbeans 11 mit OpenJDK 12 IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 6
MiMa JavaFX in Netbeans 11 installieren? IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 32
G NetBeans Netbeans 8.2 hängt sich auf IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 15
W Netbeans and Git Projects IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 1
J NetBeans Dokumentation anderer Projekte IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 2
N Weder Eclipse noch Netbeans funktionieren auf Ubuntu 18.04 IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 0
J NetBeans Download NetBeans und Java SDK IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 3
MiMa compile with -Xlint bei Netbeans IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 3
C Netbeans Meldung: Git Push Failed IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 8
TheJavaKid NetBeans JDBC Library mit Netbeans in Jarfile mit packen IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 13
J Netbeans: Einsicht in den Programmlauf IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 3
J NetBeans Notizen IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 2
C maven startet jetty, netbeans "run" startet glassfish IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 4
L NetBeans NetBeans autofill einrichten IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 4
pcfreak9000 Eclipse Netbeans generics IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 1
K Netbeans + Maven: default pom Inhalt IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 2
B IDE Netbeans und Eclipse IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 1
M Netbeans CSS code completion abgeschaltet IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 5
TomatenBrot447 Netbeans ziegt mir falsche Tasteneingabe an IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 2
wolfgang63 Netbeans 8.2 ohne Projektvorlagen IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 2
MiMa Ist Netbeans mist ??? IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 14
K easy UML Plugin Netbeans 8.1 IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 1
WetWer NetBeans Wird NetBeans eigentlich noch unterstützt? IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 2
F Netbeans Overriden - @ IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 4
Tort-E NetBeans Netbeans RCP Spracheinstellungen IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 1
M Netbeans GUI Builder größe ändern IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 0
Y Tomcat aus Netbeans heraus starten schlägt fehl IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 1
A Login-Programmierung mit NetBeans IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 7
H Kann ich Commandline-Parameter in Eclipse oder Netbeans einfacher übergeben? IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 5
F Netbeans Pfad IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 2
D NetBeans Maven Projekt in Netbeans => WEKA wirft (java.lang.OutOfMemoryError: Java heap space) IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 0
S NetBeans 8.0.2: Startprogramm meldet: Hilfsprogramm für den Tastaturverlauf funktioniert nicht mehr IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 3
A in netbeans 8 mit jdk 8 erstellte jar's laufen nicht auf anderen rechnern ohne jdk IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 4
L NetBeans und Ausgabenumlenkung in Datei IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 0
T NetBeans - Tastatur-Tricks IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 2
M NetBeans und UTF8 Problem IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 1
J Javadocs in Netbeans 7.4 dt. integrieren IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 4
D [NetBeans] NetBeans Plattform Application Fragen IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 0
Y (NetBeans JSP) Findet @page import="org.apache.commons.fileupload.* nicht IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 6
C Netbeans - keine Sourcen in jar IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 0
M NetBeans JavaDB Exception IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 1
N Netbeans import/export IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 2
F NetBeans JLable Text ändern? IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 3
MiMa Hin und her gerissen Netbeans und Eclipse IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 6
A Checkstyle + Netbeans + cfg File IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 8
B NetBeans GUI Vererbung mit Netbeans IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 3
J NetBeans Netbeans, Linux -> Was ist ein "bootstrap class path error" und wie kann man das wegbekommen? IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 3
D C++ mit NetBeans benutzen. IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 2
C Pfad von .netbeans ändern IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 6
D GUI Building in NetBeans nur mit Zusatztool möglich? IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 3
S Umstieg auf Netbeans ... ? IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 2
Jackii NetBeans Netbeans 7 Splash Screen erstellen IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 10
T MDI-Anwendung mit NetBeans IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 3
D NetBeans NetBeans Shortcuts IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 3
Guybrush Threepwood Jar-Export unter Netbeans (vs. Eclipse) IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 2
H Netbeans löscht Quelldatein IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 2
P Netbeans: Java-Plattformen verwalten IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 2
G Netbeans WS Client Clean and Build IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 2
H Test Project (x) Netbeans IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 3
L NetBeans 7.1 swing IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 9
L javafx import in NetBeans IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 2

Ähnliche Java Themen

Neue Themen


Oben