How to make chat(whatsapp like) ui in java swing using MigLayout

540 Views Asked by At

I want to add components to MigLayout which i can add as sent/recieved message, just like this:

--------------------------------------------
| received message                         |

|                              sent Message|
--------------------------------------------

I have created following constructor:

new MigLayout(
        // set the automatic wrap after columns
        "insets 0, wrap 0", 
        // hardcode fixed column width and fixed column gap 
        "", 
        // hardcode fixed height and a zero row gap
        "[]10"));

while adding a component if i use "push, al right" it doest the job for me but the components take average space of height as shown in link below:

enter image description here

so all i want is these components one after another with only gap specified(10) in constructor. Thanks

1

There are 1 best solutions below

0
camickr On BEST ANSWER

Try something like:

JPanel parent = JPanel( new BorderLayout() );
parent.add(yourPanelUsingMigLayout, BorderLayout.PAGE_START);
frame.add(parent);

The BorderLayout.PAGE_START will respect the preferred height of the component. Therefore you should not see vertical space between components.