i'm trying to create a JLabel that has text aligned left and icon aligned right, i tried this code:
_ip = new JLabel(ip);
_ip.setFont(boldFont);
_ip.setBounds(5, 0, 100, 50);
_ip.setIcon(images.ipBan);
_ip.setBorder(BorderFactory.createLineBorder(Color.black, 1));
_ip.setHorizontalTextPosition(SwingConstants.LEFT);
add(_ip);
And this is what i get:
The red image shows the actual image alignment, the gray one shows where i want my image to be.
If i add
_ip.setAlignmentX(JLabel.RIGHT_ALIGNMENT);
Nothing happens, and if i add
_ip.setHorizontalAlignment(JLabel.RIGHT);
Icon is aligned right, but also text is aligned right, and i want it to align left
Is there a way to do it?
Alternatively, you can use a JPanel with a suitable layout, as shown here.
please DYM???
import java.awt.*;
import javax.swing.*;
public class CenteredJLabel {
private JFrame frame = new JFrame("Test");
private JPanel panel = new JPanel();
private JLabel label = new JLabel("CenteredJLabel");
private Icon errorIcon = UIManager.getIcon("OptionPane.errorIcon");
public CenteredJLabel() {
panel.setLayout(new GridBagLayout());
panel.add(label);
label.setHorizontalAlignment(SwingConstants.LEFT);
label.setVerticalAlignment(SwingConstants.CENTER);
label.setIcon(errorIcon);
label.setIconTextGap(20);
label.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
panel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.add(panel);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
#Override
public void run() {
CenteredJLabel centeredJLabel = new CenteredJLabel();
}
});
}
}
EDIT
import java.awt.*;
import javax.swing.*;
public class CenteredJLabel {
private JFrame frame = new JFrame("Test");
private JPanel panel = new JPanel();
private JLabel labelOne = new JLabel("CenteredJLabel");
private JLabel labelTwo = new JLabel("1.1.1.1");
private JLabel labelThree = new JLabel("192.168.255.255");
private JLabel labelFour = new JLabel("192.168.255.255");
private Icon errorIcon = UIManager.getIcon("OptionPane.errorIcon");
private Icon infoIcon = UIManager.getIcon("OptionPane.informationIcon");
private Icon warnIcon = UIManager.getIcon("OptionPane.warningIcon");
private Icon questnIcon = UIManager.getIcon("OptionPane.questionIcon");
private JPanel panelTwo = new JPanel();
public CenteredJLabel() {
panel.setLayout(new GridLayout(4, 0, 10, 10));
labelOne.setHorizontalAlignment(SwingConstants.LEFT);
labelOne.setVerticalAlignment(SwingConstants.CENTER);
labelOne.setIcon(errorIcon);
labelOne.setIconTextGap(20);
labelOne.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
panel.add(labelOne);
labelTwo.setHorizontalAlignment(SwingConstants.LEFT);
labelTwo.setVerticalAlignment(SwingConstants.CENTER);
labelTwo.setIcon(infoIcon);
labelTwo.setIconTextGap(20);
labelTwo.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
panel.add(labelTwo);
labelThree.setHorizontalAlignment(SwingConstants.LEFT);
labelThree.setVerticalAlignment(SwingConstants.CENTER);
labelThree.setIcon(warnIcon);
labelThree.setIconTextGap(20);
labelThree.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
panel.add(labelThree);
panelTwo.setLayout(new BorderLayout());
panelTwo.setOpaque(false);
panelTwo.add(labelFour, BorderLayout.WEST);
panelTwo.add(new JLabel(questnIcon), BorderLayout.EAST);
panel.add(panelTwo);
panel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.add(panel);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
#Override
public void run() {
CenteredJLabel centeredJLabel = new CenteredJLabel();
}
});
}
}
Related
I need to insert the window with the tabbed called "First panel, Second panel, Third panel, Fourth panel" into the window named "Animation".
What should I do so that at the end it looks like: a window that has an animation box with four tabs, a Text box and a User input box?
First class called "Main" :
import java.awt.*;
import javax.swing.*;
public class Main {
JFrame frame = new JFrame("Demo");
JPanel panel = new JPanel();
JLabel square1 = new JLabel("Animation");
JLabel square2 = new JLabel("Text");
JTextField square3 = new JTextField("User Input");
public Main() {
panel.setLayout(new GridLayout(2,2,3,3));
panel.add(square1);
panel.add(square2);
panel.add(square3);
frame.add(panel);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.pack();
frame.setSize(600,400);
frame.setVisible(true);
}
public static void main(String[] args) {
Tabbed tp = new Tabbed();
tp.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
tp.setSize(600,400);
tp.setVisible(true);
SwingUtilities.invokeLater(new Runnable() {
#Override
public void run() {
new Main();
}
});
}
}
'Second class called "Tabbed" :'
import javax.swing.*;
public class Tabbed extends JFrame{
private static final long serialVersionUID = 1L;
JPanel firstPanel = new JPanel();
JPanel secondPanel = new JPanel();
JPanel thirdPanel = new JPanel();
JPanel fourPanel = new JPanel();
JLabel firstLabel = new JLabel("First!");
JLabel secondLabel = new JLabel("Second!");
JLabel thirdLabel = new JLabel("Third!");
JLabel fourLabel = new JLabel("Fourth!");
JTabbedPane tabbedPane = new JTabbedPane();
public Tabbed(){
firstPanel.add(firstLabel);
secondPanel.add(secondLabel);
thirdPanel.add(thirdLabel);
fourPanel.add(fourLabel);
tabbedPane.add("First panel",firstPanel);
tabbedPane.add("Second panel",secondPanel);
tabbedPane.add("Third panel",thirdPanel);
tabbedPane.add("Fourth panel",fourPanel);
add(tabbedPane);
}
}
Here's how I want to combine the two windows :
Hello I am having a problem adding buttons to my GUI, I try to use BorderLayout to add the buttons but it does not show when I run. Since using BorderLayout my choice of background color reverts to white as well. Can anyone please help?
import javax.swing.*;
import java.awt.*;
public class BlackjackGUI{
private JFrame frame;
private JPanel panel;
private JButton newGameBtn, dealBtn, hitBtn, standBtn;
private JLabel playerMoneyLbl;
private JLabel playerCard1Lbl, playerCard2Lbl, playerCard3Lbl,
playerCard4Lbl, playerCard5Lbl, playerCard6Lbl, playerCard7Lbl;
private JLabel dealerCard1Lbl, dealerCard2Lbl, dealerCard3Lbl, dealerCard4Lbl,
dealerCard5Lbl, dealerCard6Lbl, dealerCard7Lbl;
private JLabel playerCardValueLbl, dealerCardValueLbl;
private JTextField betInputBox;
public BlackjackGUI(){
createForm();
addButtons();
frame.add(panel);
frame.setVisible(true);
}
public void createForm() {
JFrame frame = new JFrame("Blackjack");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(1200,800);
frame.setVisible(true);
JPanel panel = new JPanel();
Color c = new Color(0, 100, 0);
panel.setBackground(c);
panel.setLayout(new BorderLayout());
}
public void addButtons() {
newGameBtn = new JButton("New Game");
panel.add(newGameBtn, BorderLayout.NORTH);
}
public static void main(String[] args) {
new BlackjackGUI();
}
}
I know there were similar questions but I have some different problem...
I'd like to remove all elements of JFrame after clicking a button:
It works:
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0)
{
frame.getContentPane().removeAll();
frame.revalidate();
frame.repaint();
}
});
All elements disappeared. But after that I need to putelements on this JFrame... After these 3 lines above (below frame.repaint()) I call method initialize (method that I call when I create my window at the beginning):
private void initialize()
{
frame = new JFrame();
frame.setBounds(100, 100, 1454, 860);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
JButton btnNewSubject = new JButton("New subject");
btnNewSubject.setBounds(647, 788, 137, 23);
frame.getContentPane().add(btnNewSubject);
JButton btnRefresh = new JButton("Refresh");
btnRefresh.setBounds(1339, 788, 89, 23);
frame.getContentPane().add(btnRefresh);
JLabel lblNewLabel = new JLabel("Subject");
lblNewLabel.setBounds(235, 11, 75, 14);
frame.getContentPane().add(lblNewLabel);
JLabel lblOwner = new JLabel("Owner");
lblOwner.setBounds(662, 11, 46, 14);
frame.getContentPane().add(lblOwner);
JLabel lblStatus = new JLabel("Status");
lblStatus.setBounds(883, 11, 46, 14);
frame.getContentPane().add(lblStatus);
JLabel lblDateOfAdded = new JLabel("Date of added");
lblDateOfAdded.setBounds(1104, 11, 116, 14);
frame.getContentPane().add(lblDateOfAdded);
}
Nothing happens. :( JFrame is still empty. Even if I call revalidate and repaint().
What is wrong?
You are creating a completely new JFrame in your method here
frame = new JFrame();
and you never display it, you never call setVisible(true) on it, and so it will remain invisible. It almost sounds as if you're creating two JFrames without realizing it, that you are adding components to the second non-displayed JFrame, but are leaving displaying just the first one, the one without new components.
More importantly, you will want to use a CardLayout to help you swap your JPanel views as this situation is exactly what it's built for. Also, Your program uses null layout and setBounds(...) something that results in a rigid GUI that may look good on one system but will usually look poor on any other system or screen resolution. Programs created this way are very hard to debug, maintain and upgrade. Instead use the layout managers as this is what they excel at: at creating complex flexible GUI's that can be enhanced and changed easily.
Note that your removeAll() call does not remove the root pane as Ludovic is stating because you're calling this on the contentPane not the JFrame, and the contentPane does not contain the root pane.
Edit
For example,
import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
public class CardLayoutEg extends JPanel {
private CardLayout cardlayout = new CardLayout();
private TitlePanel titlePanel = new TitlePanel(this);
private SubjectPanel subjectPanel = new SubjectPanel(this);
public CardLayoutEg() {
setLayout(cardlayout);
add(titlePanel, titlePanel.getName());
add(subjectPanel, subjectPanel.getName());
}
public void nextCard() {
cardlayout.next(this);
}
public void showCard(String key) {
cardlayout.show(this, key);
}
private static void createAndShowGui() {
JFrame frame = new JFrame("CardLayout Example");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(new CardLayoutEg());
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGui();
}
});
}
}
class TitlePanel extends JPanel {
public static final String TITLE_PANEL = "title panel";
private static final int PREF_W = 900;
private static final int PREF_H = 750;
private static final String TITLE = "My Application Title";
private static final float POINTS = 46f;
private CardLayoutEg cardLayoutEg;
public TitlePanel(CardLayoutEg cardLayoutEg) {
setName(TITLE_PANEL);
this.cardLayoutEg = cardLayoutEg;
JLabel titleLabel = new JLabel(TITLE, SwingConstants.CENTER);
titleLabel.setFont(titleLabel.getFont().deriveFont(Font.BOLD, POINTS));
JButton subjectButton = new JButton(new SubjectAction("Subjects"));
JPanel buttonPanel = new JPanel();
buttonPanel.add(subjectButton);
setLayout(new BorderLayout());
add(titleLabel, BorderLayout.CENTER);
add(buttonPanel, BorderLayout.PAGE_END);
}
#Override
public Dimension getPreferredSize() {
if (isPreferredSizeSet()) {
return super.getPreferredSize();
}
return new Dimension(PREF_W, PREF_H);
}
private class SubjectAction extends AbstractAction {
public SubjectAction(String name) {
super(name);
int mnemonic = (int) name.charAt(0);
putValue(MNEMONIC_KEY, mnemonic);
}
#Override
public void actionPerformed(ActionEvent e) {
cardLayoutEg.showCard(SubjectPanel.SUBJECT_PANEL);
}
}
}
class SubjectPanel extends JPanel {
public static final String SUBJECT_PANEL = "subject panel";
private static final String[] COLUMN_NAMES = {"Subject", "Owner", "Status", "Date Added"};
DefaultTableModel tableModel = new DefaultTableModel(COLUMN_NAMES, 10);
private JTable table = new JTable(tableModel);
private CardLayoutEg cardLayoutEg;
public SubjectPanel(CardLayoutEg cardLayoutEg) {
setBorder(BorderFactory.createTitledBorder("Subject Panel"));
setName(SUBJECT_PANEL);
this.cardLayoutEg = cardLayoutEg;
JPanel buttonPanel = new JPanel();
buttonPanel.setLayout(new GridLayout(1, 0, 10, 0));
buttonPanel.add(new JButton("New Subject"));
buttonPanel.add(new JButton("Refresh"));
buttonPanel.add(new JButton(new TitleAction("Title")));
buttonPanel.add(new JButton(new ExitAction("Exit")));
JPanel bottomPanel = new JPanel();
bottomPanel.setLayout(new BoxLayout(bottomPanel, BoxLayout.LINE_AXIS));
bottomPanel.add(Box.createHorizontalGlue());
bottomPanel.add(buttonPanel);
setLayout(new BorderLayout());
add(new JScrollPane(table), BorderLayout.CENTER);
add(bottomPanel, BorderLayout.PAGE_END);
}
private class TitleAction extends AbstractAction {
public TitleAction(String name) {
super(name);
int mnemonic = (int) name.charAt(0);
putValue(MNEMONIC_KEY, mnemonic);
}
#Override
public void actionPerformed(ActionEvent e) {
cardLayoutEg.showCard(TitlePanel.TITLE_PANEL);
}
}
private class ExitAction extends AbstractAction {
public ExitAction(String name) {
super(name);
int mnemonic = KeyEvent.VK_X;
putValue(MNEMONIC_KEY, mnemonic);
}
#Override
public void actionPerformed(ActionEvent e) {
Component component = (Component) e.getSource();
Window win = SwingUtilities.getWindowAncestor(component);
win.dispose();
}
}
}
I'm trying to make a deck manager for a card game (Yu-Gi-Oh :D), and for now I only have a table with available cards and a panel that shows the card the user selected in a bigger size and with the card's description.
MVCE:
import java.awt.*;
import javax.swing.*;
public class SelectedCardPanel extends JPanel{
private final JLabel cardArea;
private final JTextArea cardInfo;
public static void main(String args[]){
java.awt.EventQueue.invokeLater(new Runnable() {
#Override
public void run() {
JFrame frame = new JFrame("Yu-Gi-Oh!");
frame.add(new SelectedCardPanel());
frame.pack();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
});
}
public SelectedCardPanel(){
super();
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
setPreferredSize(new Dimension(200, 400));
cardArea = new JLabel(" ");
cardArea.setOpaque(true);
cardArea.setBackground(Color.white);
cardArea.setPreferredSize(new Dimension(200, 300));
cardArea.setSize(cardArea.getPreferredSize());
cardArea.setBorder(BorderFactory.createLineBorder(Color.black));
cardInfo = new JTextArea();
cardInfo.setEditable(false);
cardInfo.setWrapStyleWord(true);
cardInfo.setLineWrap(true);
cardInfo.setPreferredSize(new Dimension(200, 100));
cardInfo.setBorder(BorderFactory.createLineBorder(Color.black));
add(cardArea);
add(cardInfo);
}
public final void setImage(ImageIcon icon){
cardArea.setIcon(icon);
}
}
But that's what happens:
In the MVCE:
The cardArea gets to the right, and I don't understand why.
The card I select in the Table goes without problems to the selected card panel.
Why is the JLabel getting to the right?
The problem is with the BoxLayout. I would instead recommend using a BorderLayout And get rid of all the set[Preferred]Sizes. As for the text area, use the constructor JTextArea(rows, cols). For the columns you can leave at 0, and with BorderLayout, it will stretch to match the width of the image
import java.awt.*;
import javax.swing.*;
public class SelectCardPanel extends JPanel{
private final JLabel cardArea;
private final JTextArea cardInfo;
public static void main(String args[]){
java.awt.EventQueue.invokeLater(new Runnable() {
#Override
public void run() {
JFrame frame = new JFrame("Yu-Gi-Oh!");
SelectCardPanel panel = new SelectCardPanel();
panel.setImage(new ImageIcon(SelectCardPanel.class.getResource("images.jpg")));
frame.add(panel);
frame.pack();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
});
}
public SelectCardPanel(){
super();
setLayout(new BorderLayout());
//setPreferredSize(new Dimension(200, 400));
cardArea = new JLabel();
cardArea.setOpaque(true);
cardArea.setBackground(Color.white);
//cardArea.setPreferredSize(new Dimension(200, 300));
//cardArea.setSize(cardArea.getPreferredSize());
cardArea.setBorder(BorderFactory.createLineBorder(Color.black));
cardInfo = new JTextArea(5, 0);
cardInfo.setEditable(false);
cardInfo.setWrapStyleWord(true);
cardInfo.setLineWrap(true);
//cardInfo.setPreferredSize(new Dimension(200, 100));
cardInfo.setBorder(BorderFactory.createLineBorder(Color.black));
add(cardArea);
add(cardInfo, BorderLayout.PAGE_END);
}
public final void setImage(ImageIcon icon){
cardArea.setIcon(icon);
}
}
I wrote a program to compose a GUI using swing/awt framework for my assignment. So far, I am able to get the pieces working together, but when I put them all into a JFrame, they are not coming out as expected.
I have recently started working on Java GUI framework, and not sure what is missing in my code. How can I get this working properly?
I am also attaching the screen shots (see at the bottom) of the output I am getting.
public class MainFrame extends JFrame {
public MainFrame() {
addComponentsToPane(this.getContentPane());
}
private void addComponentsToPane(Container pane) {
// Set layout
GridBagConstraints gbc = new GridBagConstraints();
this.setTitle("Test tool");
this.setSize(600, 650);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLayout(new GridLayout(2, 1));
// Add video JComponent
mMainPanel = new MainPanel();
pane.add(mMainPanel, 0);
// Add conference screen panel
mFeedPanel = new FeedPanel();
pane.add(mFeedPanel, 1);
// Add a button panel
mButtonPanel = new ButtonPanel();
pane.add(mButtonPanel, 2);
this.setResizable(true);
this.setVisible(true);
this.pack();
}
}
// In actual output, there is 1 screen in this panel.
// mScreen1 is derived from JComponent object.
public class MainPanel() extends JPanel {
public MainPanel() {
addMainPanelComponents();
}
private void addMainPanelComponents() {
this.setSize(352, 240);
setBackground(Color.yellow);
setLayout(new GridLayout(1, 2));
add(mScreen);
setVisible(true);
}
}
// In actual output, there are 3 screens in this panel. I have shown code for 1 screen only
// mScreen1 is derived from JComponent object.
public class FeedPanel extends JPanel {
public FeedPanel() {
addFeedPanelComponents();
}
private void addFeedPanelComponents() {
String img1 = "images/screen1.png";
setSize(352, 150);
setBackground(Color.yellow);
setLayout(new GridLayout(1, 3));
Image image1 = ImageIO.read(new File(img1));
mScreen1.setImage(image1);
add(mScreen1);
setVisible(true);
}
}
public class ButtonPanel extends JPanel {
public ButtonPanel() {
addButtonPanelComponents();
}
private void addButtonPanelComponents() {
this.setSize(352, 150);
this.setBackground(Color.yellow);
this.setLayout(new GridLayout(1,
5));
// Add Button to panel
mStartButton = new JButton("Start");
this.add(mStartButton);
mStartButton.addActionListener(new ActionListener() {
#Override
public void actionPerformed(ActionEvent ae) {
StartButtonActionListener(ae);
}
});
mStopButton = new JButton("Stop");
this.add(mStopButton);
mStopButton.addActionListener(new ActionListener() {
#Override
public void actionPerformed(ActionEvent ae) {
StopButtonActionListener(ae);
}
});
setVisible(true);
}
}
This comes by default on running the code.
This comes after manually resizing the frame.
The combination of BorderLayout , GirdLayout and BoxLayout can do this for you(Actually it's not the only choice).
Here is the code:
import java.awt.BorderLayout;
import java.awt.GridLayout;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class GridLayoutTest {
public void createUI(){
JFrame frame = new JFrame();
JPanel topPanel = new TopPanel();
JPanel buttomPanel = new ButtomPanel();
JPanel mainPanel = new JPanel();
mainPanel.setLayout(new BorderLayout());
mainPanel.add(topPanel,BorderLayout.CENTER);
mainPanel.add(buttomPanel,BorderLayout.SOUTH);
frame.add(mainPanel,BorderLayout.CENTER);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
public static void main(String[] args) {
GridLayoutTest test = new GridLayoutTest();
test.createUI();
}
#SuppressWarnings("serial")
class TopPanel extends JPanel{
public TopPanel(){
setLayout(new GridLayout(2, 3));
ImageIcon icon = new ImageIcon("capture.png");
JLabel label1 = new JLabel(icon);
label1.setVisible(false);
JLabel label2 = new JLabel(icon);
JLabel label3 = new JLabel(icon);
label3.setVisible(false);
JLabel label4 = new JLabel(icon);
JLabel label5 = new JLabel(icon);
JLabel label6 = new JLabel(icon);
add(label1);
add(label2);
add(label3);
add(label4);
add(label5);
add(label6);
}
}
#SuppressWarnings("serial")
class ButtomPanel extends JPanel{
public ButtomPanel(){
JButton startButton = new JButton("start");
JButton stopButton = new JButton("stop");
JButton recordButton = new JButton("record");
setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
add(Box.createHorizontalGlue());
add(startButton);
add(Box.createHorizontalStrut(10));
add(stopButton);
add(Box.createHorizontalStrut(10));
add(recordButton);
add(Box.createHorizontalGlue());
}
}
}
BoxLayout is so good too provide white space and help you to center the component.
setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
add(Box.createHorizontalGlue());
add(startButton);
add(Box.createHorizontalStrut(10));
add(stopButton);
add(Box.createHorizontalStrut(10));
add(recordButton);
add(Box.createHorizontalGlue());
Add Glue before the first component and after the last component will help you too center the component and add strut can help you to provide white space you want. you can refer to https://stackoverflow.com/a/22525005/3378204 for more details.
Here is the effect:
The BoxLayout won't affect your component's size. Hope it can help you.
Try this :
public class Main{
private JFrame f;
private JLabel l1, l2, l3,l4;
private JPanel p1, p2, p3;
private JButton b1, b2, b3;
public Main(){
this.f = new JFrame();
this.f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.f.setLayout(new GridLayout(3,1));
this.p1 = new JPanel();
this.p1.setLayout(null)
this.p1.setSize(yoursize);
this.l1 = new JLabel();
this.l1.setBounds(x,y,xspan,yspan);
this.p1.add(l1);
this.p2 = new JPanel();
this.p2.setLayout(new GridLayout(1,3));
this.l2 = new JLabel();
this.l3 = new JLabel();
this.l4 = new JLabel();
this.p2.add(l2);
this.p2.add(l3);
this.p2.add(l4);
this.p3 = new JPanel();
this.p3.setLayout(new GridLayout(1,3));
this.b1 = new JButton();
this.b2 = new JButton();
this.b3 = new JButton();
this.p3.add(b1);
this.p3.add(b2);
this.p3.add(b3);
this.f.add(p1);
this.f.add(p2);
this.f.add(p3);
this.f.pack();
this.f.setResizeable(false)
}}
Add your video components instead of labels and you can change the color of the components as you wish.
Also if you want more control over the size and position of the components, use null layout and place them individually using setBounds() function as once shown in the program above. It is surely time consuming but makes the layout perfect.