swing - How to change the position of label in frame using java -
I have just started creating frames in Java and have written the following code:
Import javax.swing *. Public class hello word frame extends JFrame {public static zero main (string [] args) {new hello frame (); } HelloWaldFrime () {JLAB JLB = New JLab ("HelloWald"); (JLB); This.setSize (100,100); SetVisible (true); }} Can anyone help explain how I can change the status of the labels in the above code
Actually using two handing methods is quite easy to change the position of its JLable frequency. See below to use code:
HelloWaldFrame () {JLabel jlb = new JLab ("HelloWald"); Jlb.setHorizontalAlignment (50); // set horizontal alignment on X axis! Jlb.setVerticalAlignment (50); Set vertical alignment on // y axis! (JLB); This.setSize (100,100); SetVisible (true); } You can learn more about JLABEL and how to manipulate them here:
// EDITS
Aadhaar on the comment I gave earlier, which did not give the given alignment work. That's why I made the necessary changes to work them!
HelloWaldFrame () {JLAB JLB = New JLab ("HelloWald"); Jlb.setHorizontalAlignment (SwingConstants.CENTER); // set horizontal alignment on X axis! Jlb.setVerticalAlignment (SwingConstants.CENTER); Set vertical alignment on // y axis! (JLB); This.setSize (100,100); SetVisible (true); }
Comments
Post a Comment