0

I'm completely new to Layout Managers, but i want to create a table. I have a window that is set.Resizable(false) and doesn't have a layout manager, with 1 image and two text items placed using coordinates. I would like to keep these items using absolute layout, while creating my table underneath (using GridLayout I assume)

If it helps, here is my code:

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
        {
        }
    }
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Blaine
  • 332
  • 1
  • 4
  • 18
  • Typically you would want a container panel that holds all the components for your GUI, then you would set that JPanel to the layout you desire. – Wyatt Lowery Nov 18 '15 at 12:44
  • what if you only want some of the gui components to be laid out in that way? – Blaine Nov 18 '15 at 12:55
  • 1
    Variable names should NOT start with an upper case characters. Don't use static variables. You should NOT use a null layout and setBounds(). Swing was designed to be used with layout managers. – camickr Nov 18 '15 at 19:02
  • 2
    About the `null` layout.. Java GUIs have to work on different OS', screen size, screen resolution etc. using different PLAFs in different locales. As such, they are not conducive to pixel perfect layout. Instead use layout managers, or [combinations of them](http://stackoverflow.com/a/5630271/418556) along with layout padding and borders for [white space](http://stackoverflow.com/a/17874718/418556). – Andrew Thompson Nov 18 '15 at 19:09

0 Answers0