如何同时使用两个布局管理器?

时间:2015-11-18 12:33:21

标签: java swing layout layout-manager null-layout-manager

我是布局管理员的新手,但我想创建一个表格。我有一个set.Resizable(false)的窗口,没有布局管理器,有1个图像和两个使用坐标放置的文本项。我想使用绝对布局保留这些项目,同时在下面创建我的表格(使用GridLayout我假设)

如果有帮助,这是我的代码:

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.Canvas;
import javax.swing.JFrame;
import java.awt.Dimension;

class DisplayItems extends JFrame implements ActionListener 
{
    //text
    private static JLabel TechforTeachingTitle;
    private static JLabel TechforTeachingSubTitle;

    //images
    private static JLabel Logo;

    //buttons

    private static final int BUTTON_WIDTH = 100;
    private static final int BUTTON_HEIGHT = 30;

    public static void main(String[] args) 
    {

        DisplayItems ProjectFrame = new DisplayItems();  
        ProjectFrame.setVisible(true); // Display the frame


    }

    public DisplayItems( ) 
    {
        //font properties
        Font TitleFont = new Font("Serif", Font.BOLD, 80);
        Font subFont = new Font("Serif", Font.BOLD, 40);

        // set the frame properties
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setTitle("Inventory system");
        setSize(900, 700);
        setLocationRelativeTo(null);
        setResizable(false);

        // set the content pane properties
        Container contentPane = getContentPane();   
        contentPane.setLayout(null);
        contentPane.setBackground(Color.decode("#FDF3E7"));

        //set text properties
        TechforTeachingTitle = new JLabel();     
        TechforTeachingTitle.setText("Tech For Teaching"); 
        TechforTeachingTitle.setBounds(200, 30, 900, 95); 
        TechforTeachingTitle.setForeground(Color.decode("#8f8f8f"));
        TechforTeachingTitle.setFont(TitleFont);
        contentPane.add(TechforTeachingTitle);

        TechforTeachingSubTitle = new JLabel();     
        TechforTeachingSubTitle.setText("View items"); 
        TechforTeachingSubTitle.setBounds(400, 90, 900, 95); //left, top, length, height
        TechforTeachingSubTitle.setForeground(Color.decode("#799177"));   //7E8F7C (slightly less green)
        TechforTeachingSubTitle.setFont(subFont);
        contentPane.add(TechforTeachingSubTitle);

        //set image properties
        Logo = new JLabel(new ImageIcon("SmallLogo.png")); 
        Logo.setBounds(10,20,179,178); // //left, top, width, height
        contentPane.add(Logo);
        Logo.setVisible(true);
    //         Logo.addMouseListener(new MouseAdapter()
    //             {
    //                 public void mouseClicked(MouseEvent e) {
    //                     setVisible(false);
    // 
    //                     FinalProject FP = new FinalProject(); 
    //                     FP.setVisible(true); 
    //                 }
    //             });
            //set button properties

        }



          public void actionPerformed(ActionEvent event) // Actions
        {
        }
    }

0 个答案:

没有答案