I want try to use miglayout because it is more flexible. I try to add date and some button, but after i use wrap, the gap between the button is inventory and transaction become far but between transaction button and add item button is ok.
This is my code:
top = new JPanel();
top.setLayout(new MigLayout("","",""));
center = new JPanel();
bottom = new JPanel();
right = new JPanel();
left = new JPanel();
inventory = new JButton("Inventory");
transaction = new JButton("Transaction");
addItem = new JButton("Add Item");
date = new Date();
dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
dateTime = new JLabel(dateFormat.format(date));
top.add(dateTime,"wrap");
dateTime.setBorder(BorderFactory.createLineBorder(Color.red));
top.add(inventory);
inventory.setBorder(BorderFactory.createLineBorder(Color.red));
top.add(transaction);
transaction.setBorder(BorderFactory.createLineBorder(Color.red));
top.add(addItem);
addItem.setBorder(BorderFactory.createLineBorder(Color.red));
add(top,BorderLayout.NORTH);
Display:
----------------------------------------------
2013/12/09 13.09.15
[Inventory] [Transaction] [Add Item]
Based on your code I've made a SSCCE to easily show your problem. Next time this task is up to you. Note: I've removed the custom borders and the other panels since these are irrelevant to the problem.
Currently your top panel looks like this:
There are several ways to achieve your goal, you just need to play around with constraints. For instance you can do as follows:
And you'll see something like this:
Or you can define 3 columns and span 3 cells in the first row, as follows:
The outcome would be similar to the previous one.
For further information take a look to Quick Start guide