user3016272
user3016272

Reputation:

How to Align buttons in Java i try some of the ways but but not working in my code any clue what i do to solve this

here is my code:

    bbtn = new JButton("Brightness");

    bbtn.setLayout(new BoxLayout(bbtn, BoxLayout.LINE_AXIS));

    bbtn.setBorderPainted(false);

    bbtn.setAlignmentX(LEFT_ALIGNMENT);

    bbtn.setAlignmentY(TOP_ALIGNMENT);

    bbtn.setBackground(Color.white);

    ImageIcon img = new ImageIcon("C:\\Documents and Settings\\omi\\My Documents\\NetBeansProjects\\JavaApplicationEditor\\src\\utilities_brightness.png");

    bbtn.setIcon(img);

    mpanel.add(bbtn);

setAlignement lines are not working i've also try the setBounds but still not working

Upvotes: 0

Views: 58

Answers (1)

BilalDja
BilalDja

Reputation: 1092

You should put your JButton on a Container, and sets the layout manager of your container to feat the left alignment. This is a example maybe inspire you :

JPanel thePanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
JButton theButton = new JButton("Britness");

thePanel.add(theButton);

Hope that helps, Salam

Upvotes: 1

Related Questions