I have the below image. It consists of a JPanel containing one label for the picture, another one for the '@usuario1' text, another one for 'contenido', and another one for '#demo'. Below the image is the code which constructs it.
SettingsManagerTab.panelForTweet1 = new JPanel();
SettingsManagerTab.panelForTweet1.setOpaque(true);
SettingsManagerTab.panelForTweet1.setLayout(new net.miginfocom.swing.MigLayout());
this.add(SettingsManagerTab.panelForTweet1);
SettingsManagerTab.labelForTweetPhoto1 = new JLabel(new ImageIcon(
SettingsManagerTab.class.getResource("/res/User1.png")));
SettingsManagerTab.panelForTweet1.add(SettingsManagerTab.labelForTweetPhoto1);
SettingsManagerTab.labelForTweetUsername1 = new JLabel("@usuario1");
final Font contentFont = new Font(SettingsManagerTab.labelForTweetUsername1.getFont()
.getName(), Font.BOLD, SettingsManagerTab.labelForTweetUsername1.getFont()
.getSize());
final Font userFont = new Font(contentFont.getName(), Font.BOLD,
(int) (contentFont.getSize() * 0.7));
SettingsManagerTab.labelForTweetUsername1.setFont(userFont);
SettingsManagerTab.panelForTweet1.add(SettingsManagerTab.labelForTweetUsername1);
SettingsManagerTab.labelForTweetContent1 = new JLabel("contenido");
SettingsManagerTab.labelForTweetContent1.setFont(contentFont);
SettingsManagerTab.panelForTweet1.add(SettingsManagerTab.labelForTweetContent1);
SettingsManagerTab.labelForTweetHashtag1 = new JLabel("#demo");
SettingsManagerTab.labelForTweetHashtag1.setFont(contentFont);
SettingsManagerTab.panelForTweet1.add(SettingsManagerTab.labelForTweetHashtag1);
But what I want to achieve is this:
It looked trivial to me. Simply make growy the label with the picture, and then add the '@usuario1' with wrap option so the next component (the 'contenido' label) is added at the beginning of the next line and, since the picture label is occupying all the height of the JPanel, the mentioned next line will start just below the '@usuario1' label. However what seems to happen is that the next line starts just below the picture label, but since the label is taking all the height of the JPanel, it isn't shown, so I get a result which is worse than the beginning.
Is my goal possible? And if so, how?
Go through PDF present at link for MiGLayout or you can try GridBagLayout. If you want to use GridBagLayout this link might be helpful. Using GridBagLayout you can set the component as you want.
Take reference of below example:
panel.add(comp1);
panel.add(comp2, "span 2 2"); // The component will span 2x2 cells.
panel.add(comp3, "wrap"); // Wrap to next row
panel.add(comp4);
panel.add(comp5, "wrap"); // Note that it "jumps over" the occupied cells.
panel.add(comp6);
panel.add(comp7);
O/p: