I'm new to swing This is the code I wrote
import java.awt . *; Import javax.swing. *; Public square neamine {public static zero main (string [] args) {// TODO code application logic here Jeffrey Frame = New JFram ("test"); Frame.setVisible (true); Frame.setSize (300,300); Frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); Zpean panel = new zpn (); Panel.setLayout (new gridoutout ()); AddItem (panel, new JLab ("label"), 0, 0, gridbag consultants. EAST); Frame.add (panel); } Private Static Zero Adytem (JPNell P, Jakombonant GC, Int I., Int i0, Int Aligned) {Gridbag Consultants C = New Gridbag Consultants (); C.insets = new instances (5,5,5,5); C.gridx = i; C.gridy = i0; C.anchor = align; P.add (gc, c); }
Whenever I run the program, whatever I align
parameter ( GridBagConstraints.NORTH
or as GridBagConstraints I pass)
etc ...), my label is in the center of the panel.
How do I change the label's alignment?
Thanks in advance.
The reason for this is that JLabel is the only component in your GUI. If you add more components then according to its condition, they will be set in their respective. Here's an extension of your program with an empty panel:
import java.awt. *; Import javax.swing. *; Public square neamine {public static zero main (string [] args) {// TODO code application logic here Jeffrey Frame = New JFram ("test"); Frame.setVisible (true); Frame.setSize (300,300); Frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); Zpean panel = new zpn (); Panel.setLayout (new gridoutout ()); Zeppel dropdown = new zpn (); EmptyArrested.Set expected size (new dimension (200, 200)); AddItem (panel, new JLabel ("label"), 0, 0, GridBagConstraints.WEST); AddItem (panel, empty array, 0, 0, GridBagConstraints.CENTER); Frame.add (panel); } Private Static Zero Adytem (JPNell P, Jakombonant GC, Int I., Int i0, Int Aligned) {Gridbag Consultants C = New Gridbag Consultants (); C.insets = new instances (5,5,5,5); C.gridx = i; C.gridy = i0; C.anchor = align; P.add (gc, c); }}
Comments
Post a Comment