Reputation: 2098
here's my problems : I tried to create a simple interface from where I can click on several buttons that call differents functions, and show the result (which always is text) in a jlabel.I tried to have 2 separates parts (north/south or east/west) The first area would contain a gridlayout or flowlayout of all my buttons and the 2nd area would show the text result.
Here are my declarations :
private static JButton b0 = new JButton("Creer Zone");
private static JButton b1 = new JButton("1");
private static JButton b2 = new JButton("2");
...
private static JButton b11= new JButton("11");
private static JButton b12 = new JButton("12");
private static JButton b14 = new JButton("Help");
private static JFrame windows = new JFrame();
private static JPanel container = new JPanel();
private static JLabel res = new JLabel();
and here is how i added them to the JFrame (which is really awfull to see) :
container.add(b0);
container.add(b1);
container.add(b2);
...
container.add(b12);
container.add(b14);
container.add(res);
windows.setSize(450,500);
windows.setContentPane(container);
windows.setLocation(150 , 150);
windows.setVisible(true);
I've tried to declare my jpanel with a gridlayout, a borderlayout and change the location (N S E W) and a flowlayout, i always ended up with the jlabel disapearing (which is bad because this jlabel show the result of my functions)
Any one have a simple way to help me overcome this ? Thanks a lot for any time you take
Upvotes: 1
Views: 118
Reputation: 21
Another possible solution for your future endeavors is to look into WindowsBuilder. It basically simplifies your layout design by allowing you to just simply drag and drop your elements (Jframe, JtextField, etc) and then in the background WindowsBuilder will write the code for you. Mind you the only thing that you will have to really add/change is the naming conventions of the buttons and of course the eventHandlers, but honestly those are something that any designer would want to control... Hopefully this helps you!
https://developers.google.com/java-dev-tools/wbpro/
Upvotes: 1
Reputation: 5798
nicely explained on http://docs.oracle.com/javase/tutorial/uiswing/layout/gridbag.html
Upvotes: 1