border&grid layouts

前端 未结 3 1616
北海茫月
北海茫月 2021-01-22 07:04

\"SampleHi everyone I have a problem. If anyone can help it would be great. I am using border and gridlayout and I am

3条回答
  •  一整个雨季
    2021-01-22 07:48

    This is an example of what I mentioned in the comment (with a few other tweaks).

    PanelFurniture image

    package test;
    
    import java.awt.*;
    import javax.swing.*;
    
    public class PanelFurniture extends JPanel
    {
    
        private static final long serialVersionUID = 4231608548183463223L;
    
        JButton center, east;
        // leading/trailing spaces in these labels will be ignored.
        JButton[] commandButtons = {
                new JButton("Add Chair"),
                new JButton("Add Table"),
                new JButton("Add Desk "),
                new JButton("Clear All   "),
                new JButton("Total Price"),
                new JButton("Summary "),
                new JButton("Save"),
                new JButton("Load")
        };
    
        JPanel centerPanel, eastPanel;
    
        PanelFurniture()
        {
            this.setLayout(new BorderLayout());
    
            JToolBar toolBar = new JToolBar(); 
    
            for(int i=0; i

    Update

    This GUI is based on the image.

    PanelFurniture 2

    package test;
    
    import java.awt.BorderLayout;
    import java.awt.GridLayout;
    
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.SwingUtilities;
    import javax.swing.border.EmptyBorder;
    
    public class PanelFurniture extends JPanel
    {
    
        private static final long serialVersionUID = 4231608548183463223L;
    
        JButton center, east;
        // leading/trailing spaces in these labels will be ignored.
        JButton[] commandButtons = {
                new JButton("Add Chair"),
                new JButton("Add Table"),
                new JButton("Add Desk "),
                new JButton("Clear All   "),
                new JButton("Total Price"),
                new JButton("Summary "),
                new JButton("Save"),
                new JButton("Load")
        };
    
        JPanel centerPanel, westPanel, westPanelConstrain, eastPanel;
    
        PanelFurniture()
        {
            super(new BorderLayout(2,2));
            this.setBorder(new EmptyBorder(4,4,4,4));
    
            westPanel = new JPanel(new GridLayout(0,1,4,4));
    
            for(int i=0; i

提交回复
热议问题