java - Adding JLabels to a Panel inside a Panel inside another Panel -
I have a "main" panel. I want a "side" panel inside the main one with two other panels Let's make a call to a graphic panel and a support panel. I am trying to add support labels to the main pin, but no changes have been made.
Here's my side panel:
Public square LateralSupportPane JPanel {private Final Static Ent WIDTH = 240; Personal Final Static Int HEIGHT = 740; Private GraphicPanel GP; Private Support Panel SP; Public Background Support () {this.gp = New GraphicPanel (); This.sp = new supportPanel (); This.setPreferredSize (new dimension (WIDTH, HEIGHT)); This.setLayout (new grid layout (2, 1)); //this.setBorder (BorderFactory.createLineBorder(Color.black)); This.add (gp); This.add (SP); This.setVisible (true); } Public Zero addLabel (string label) {sp.addLabel (label); } Public Zero Paint Component (Graphics G) {Superpact Component (G); Gp.paintComponent (g); } Public Zero addLabel (string label) {sp.addLabel (label); }
My support panel here:
public class supportPanel JPanel {Private Jetlet Label; Personal last fixed id WIDTH = 240; Private end constant HEIGHT = 370; Public Support Panel () {this.setPreferredSize (new dimension (WIDTH, HEIGHT)); Label = new jlab (); Label.setText ("& lt; html> blabla & lt; / html & gt;"); This.setLayout (new grid layout (10, 1)); This.add (label); This.setVisible (true); } Public JLabel getLabel () {Return Label; } Public Zero addLabel (string text) {JLabel label = new JLab (text); If (this.getComponentCount () & lt; 10) {this.add (label); } And {this. Remove (0); This.add (label); }}
From the main panel, I call Adlabel of the side panel.
EDIT: Here is the frame with all the panels. The board is a panel that has been added to one frame. The board also has another panel, which is black rectangular and areas where there is a string, together. Then the side panel is made up of 2 other panels, graphic panels (black rectangle) and support panels, this is the area where I have to apply my labels.
Confirming all the panels did not make any progress.
Not sure I want to reject it properly, but it's fast, putting a new label After you have to validate your panel;
public static zero main (string [] args) {JFrame frame = new jframe ("test"); Frame.Setset (900, 600); Frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); Frame.setLayout (New CardLayout ()); Frame.setVisible (true); Lateral SupportPan P = New LateralSamplePan (); Frame.add (p); Frame.validate (); P.addLabel ("Trial 2"); P.validate (); }
As you see, after adding a label, verification is done and the object is drawn on the form. Your method addLabel (string label)
must be called at the end of this method.
Comments
Post a Comment