-2

Project Snapshot

i want to add jscrollpane into my panel to add some more content but it is not working with panel to can any one solve this problem please hurry..... it is not appears in my panel i have tried many times but is it not working

import java.awt.Color;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JOptionPane;

import java.awt.Font;

import javax.swing.JTextField;
import javax.swing.border.EtchedBorder;
import javax.swing.border.LineBorder;
import javax.swing.JTextArea;
import javax.swing.JButton;
import javax.swing.JScrollPane;
import javax.swing.JRadioButton;
import javax.swing.JComboBox;
import javax.swing.DefaultComboBoxModel;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import java.util.Random;

public class JavaProject2_15 {

    private JFrame frame;
    private JTextField textField_6;
    private JTextField textField_5;
    private JTextField textField_4;
    private JTextField textField;
    private JTextField textField_1;
    private JTextField textField_2;
    private JTextField textField_3;
    private JComboBox comboBox;
    private JTextArea textArea;
    private static Connection con;
    private PreparedStatement PStat;
    private ResultSet res;
    private String Gender;
    private String Combobox;
    private String query;
    private JTextField textField_7;
    /**
     * Launch the application.
     */
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    JavaProject2_15 window = new JavaProject2_15();
                    window.frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * Create the application.
     */
    public JavaProject2_15() {
        initialize();
    }

    public void getDataJavaProject2_13()
    {
        frame.setVisible(true);
    }

    /**
     * Initialize the contents of the frame.
     */
    private void initialize() {

        frame = new JFrame();
        frame.setBounds(100, 100, 913, 700);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().setLayout(null);

        JPanel panel = new JPanel();
        panel.setBounds(10, 11, 877, 94);
        panel.setBorder(new LineBorder(Color.decode("#0080AA"), 2, true));
        panel.setBackground(Color.decode("#35485E"));
        frame.getContentPane().add(panel);
        panel.setLayout(null);

        JLabel lblNewLabel_1 = new JLabel("Customer Entry");
        lblNewLabel_1.setFont(new Font("Times New Roman", Font.BOLD, 20));
        lblNewLabel_1.setForeground(Color.WHITE);
        lblNewLabel_1.setBounds(380, 34, 179, 22);
        panel.add(lblNewLabel_1);

        JPanel panel_1 = new JPanel();
        panel_1.setBounds(10, 116, 689, 534);
        panel_1.setBorder(new LineBorder(Color.decode("#0080AA"), 2, true));
        frame.getContentPane().add(panel_1);
        panel_1.setLayout(null);

        JLabel lblNewLabel = new JLabel("Product Code :");
        lblNewLabel.setFont(new Font("Times New Roman", Font.PLAIN, 13));
        lblNewLabel.setBounds(37, 29, 111, 14);
        panel_1.add(lblNewLabel);

        JLabel lblCustomerName = new JLabel("Product Name :");
        lblCustomerName.setFont(new Font("Times New Roman", Font.PLAIN, 13));
        lblCustomerName.setBounds(37, 70, 111, 14);
        panel_1.add(lblCustomerName);

        JLabel lblAddress = new JLabel("Selling Price :");
        lblAddress.setFont(new Font("Times New Roman", Font.PLAIN, 13));
        lblAddress.setBounds(37, 324, 111, 14);
        panel_1.add(lblAddress);

        JLabel lblCity = new JLabel("Cost Price :");
        lblCity.setFont(new Font("Times New Roman", Font.PLAIN, 13));
        lblCity.setBounds(37, 284, 111, 14);
        panel_1.add(lblCity);

        JLabel lblState = new JLabel("Sub Category :");
        lblState.setFont(new Font("Times New Roman", Font.PLAIN, 13));
        lblState.setBounds(37, 151, 111, 14);
        panel_1.add(lblState);

        JLabel lblPincode = new JLabel("Reorder Point :");
        lblPincode.setFont(new Font("Times New Roman", Font.PLAIN, 13));
        lblPincode.setBounds(37, 364, 111, 14);
        panel_1.add(lblPincode);

        JLabel lblContactNo = new JLabel("Opening Stock :");
        lblContactNo.setFont(new Font("Times New Roman", Font.PLAIN, 13));
        lblContactNo.setBounds(37, 401, 111, 14);
        panel_1.add(lblContactNo);

        JLabel lblEmailId = new JLabel("Discount :");
        lblEmailId.setFont(new Font("Times New Roman", Font.PLAIN, 13));
        lblEmailId.setBounds(37, 439, 111, 14);
        panel_1.add(lblEmailId);

        JLabel lblRemarks = new JLabel("Remarks :");
        lblRemarks.setFont(new Font("Times New Roman", Font.PLAIN, 13));
        lblRemarks.setBounds(37, 201, 111, 14);
        panel_1.add(lblRemarks);

        textField_6 = new JTextField();
        textField_6.setFont(new Font("Times New Roman", Font.PLAIN, 13));
        textField_6.setColumns(10);
        textField_6.setBounds(135, 435, 202, 28);
        textField_6.setBorder(new LineBorder(Color.decode("#0080AA"), 2, true));
        panel_1.add(textField_6);

        textField_5 = new JTextField();
        textField_5.setFont(new Font("Times New Roman", Font.PLAIN, 13));
        textField_5.setColumns(10);
        textField_5.setBounds(135, 396, 202, 28);
        textField_5.setBorder(new LineBorder(Color.decode("#0080AA"), 2, true));
        panel_1.add(textField_5);

        textField_4 = new JTextField();
        textField_4.setFont(new Font("Times New Roman", Font.PLAIN, 13));
        textField_4.setColumns(10);
        textField_4.setBounds(135, 357, 202, 28);
        textField_4.setBorder(new LineBorder(Color.decode("#0080AA"), 2, true));
        panel_1.add(textField_4);

        textField = new JTextField();
        textField.setEditable(false);
        textField.setFont(new Font("Times New Roman", Font.PLAIN, 13));
        textField.setColumns(10);
        textField.setBounds(135, 26, 202, 28);
        textField.setBorder(new LineBorder(Color.decode("#0080AA"), 2, true));
        panel_1.add(textField);

        textField_1 = new JTextField();
        textField_1.setFont(new Font("Times New Roman", Font.PLAIN, 13));
        textField_1.setColumns(10);
        textField_1.setBounds(135, 67, 202, 28);
        textField_1.setBorder(new LineBorder(Color.decode("#0080AA"), 2, true));
        panel_1.add(textField_1);

        textField_2 = new JTextField();
        textField_2.setFont(new Font("Times New Roman", Font.PLAIN, 13));
        textField_2.setColumns(10);
        textField_2.setBounds(135, 279, 202, 28);
        textField_2.setBorder(new LineBorder(Color.decode("#0080AA"), 2, true));
        panel_1.add(textField_2);

        textField_3 = new JTextField();
        textField_3.setFont(new Font("Times New Roman", Font.PLAIN, 13));
        textField_3.setColumns(10);
        textField_3.setBounds(135, 318, 202, 28);
        textField_3.setBorder(new LineBorder(Color.decode("#0080AA"), 2, true));
        panel_1.add(textField_3);

        JScrollPane scrollPane = new JScrollPane();
        scrollPane.setBounds(135, 181, 363, 87);
        panel_1.add(scrollPane);

        textArea = new JTextArea();
        scrollPane.setViewportView(textArea);
        textArea.setBorder(new LineBorder(Color.decode("#0080AA"), 2, true));

        comboBox = new JComboBox();
        comboBox.setFont(new Font("Times New Roman", Font.PLAIN, 14));
        comboBox.setModel(new DefaultComboBoxModel(new String[] {"States Of India", "Andhra Pradesh ", "Arunachal Pradesh ", "Assam", "Bihar ", "Goa ", "Gujarat ", "Haryana ", "Himachal Pradesh", "Jammu & Kashmir", "Karnataka", "Kerala ", "Madhya Pradesh ", "Maharashtra ", "Manipur ", "Meghalaya ", "Mizoram ", "Nagaland ", "Orissa ", "Punjab", "Rajasthan ", "Sikkim ", "Tamil Nadu ", "Tripura ", "Uttar Pradesh ", "West Bengal ", "Chhattisgarh", "Uttarakhand ", "Jharkhand ", "Telangana "}));
        comboBox.setBounds(135, 145, 202, 25);
        comboBox.setBorder(new EtchedBorder(EtchedBorder.RAISED, Color.decode("#0080AA"), Color.decode("#0080AA")));
        panel_1.add(comboBox);

        JComboBox comboBox_1 = new JComboBox();
        comboBox_1.setFont(new Font("Times New Roman", Font.PLAIN, 14));
        comboBox_1.setBorder(new EtchedBorder(EtchedBorder.RAISED, Color.decode("#0080AA"), Color.decode("#0080AA")));
        comboBox_1.setBounds(135, 109, 202, 25);
        panel_1.add(comboBox_1);

        JLabel lblCategory = new JLabel("Category :");
        lblCategory.setFont(new Font("Times New Roman", Font.PLAIN, 13));
        lblCategory.setBounds(37, 116, 111, 14);
        panel_1.add(lblCategory);

        textField_7 = new JTextField();
        textField_7.setFont(new Font("Times New Roman", Font.PLAIN, 13));
        textField_7.setColumns(10);
        textField_7.setBorder(new LineBorder(Color.decode("#0080AA"), 2, true));
        textField_7.setBounds(135, 474, 202, 28);
        panel_1.add(textField_7);

        JLabel lblVat = new JLabel("VAT :");
        lblVat.setFont(new Font("Times New Roman", Font.PLAIN, 13));
        lblVat.setBounds(37, 481, 111, 14);
        panel_1.add(lblVat);

        JPanel panel_2 = new JPanel();
        panel_2.setBounds(723, 116, 164, 356);
        panel_2.setBorder(new LineBorder(Color.decode("#0080AA"), 2, true));
        frame.getContentPane().add(panel_2);
        panel_2.setLayout(null);

        JButton btnNewButton = new JButton("New ");
        btnNewButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                Customer_ID();
                textField_1.setText("");
                textField_2.setText("");
                textField_3.setText("");
                comboBox.setSelectedIndex(0);
                textField_4.setText("");
                textField_5.setText("");
                textField_6.setText("");
                textArea.setText("");
                lblVat.setText("");
            }
        });
        btnNewButton.setFont(new Font("Times New Roman", Font.PLAIN, 13));
        btnNewButton.setBounds(35, 27, 89, 40);
        btnNewButton.setBackground(Color.decode("#2788D7"));
        btnNewButton.setForeground(Color.BLACK);
        panel_2.add(btnNewButton);

        JButton btnSave = new JButton("Save");
        btnSave.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                Create();
            }
        });
        btnSave.setForeground(Color.BLACK);
        btnSave.setFont(new Font("Times New Roman", Font.PLAIN, 13));
        btnSave.setBackground(new Color(39, 136, 215));
        btnSave.setBounds(35, 80, 89, 40);
        panel_2.add(btnSave);

        JButton btnUpdate = new JButton("Update");
        btnUpdate.setForeground(Color.BLACK);
        btnUpdate.setFont(new Font("Times New Roman", Font.PLAIN, 13));
        btnUpdate.setBackground(new Color(39, 136, 215));
        btnUpdate.setBounds(35, 134, 89, 40);
        panel_2.add(btnUpdate);

        JButton btnDelete = new JButton("Delete");
        btnDelete.setForeground(Color.BLACK);
        btnDelete.setFont(new Font("Times New Roman", Font.PLAIN, 13));
        btnDelete.setBackground(new Color(39, 136, 215));
        btnDelete.setBounds(35, 185, 89, 40);
        panel_2.add(btnDelete);

        JButton btnGetdata = new JButton("Get Data");
        btnGetdata.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                JavaProject2_14 obj=new JavaProject2_14();
                obj.getDataJavaProject2_14();
            }
        });
        btnGetdata.setForeground(Color.BLACK);
        btnGetdata.setFont(new Font("Times New Roman", Font.PLAIN, 13));
        btnGetdata.setBackground(new Color(39, 136, 215));
        btnGetdata.setBounds(35, 236, 89, 40);
        panel_2.add(btnGetdata);

        JButton btnClose = new JButton("Close");
        btnClose.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                frame.setVisible(false);
            }
        });
        btnClose.setForeground(Color.BLACK);
        btnClose.setFont(new Font("Times New Roman", Font.PLAIN, 13));
        btnClose.setBackground(new Color(39, 136, 215));
        btnClose.setBounds(35, 287, 89, 40);
        panel_2.add(btnClose);
    }
}
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • 1
    What exactly is your problem? And what are you trying to do? – Tezra Jun 02 '17 at 12:25
  • i want to add jscrollpane into my panel but it is not working. it is not appears scrollbar. i want to add some more content into this panel – Mohammad Azaz Jun 02 '17 at 12:34
  • i posted snapshot with message – Mohammad Azaz Jun 02 '17 at 12:34
  • 2
    *"How To Add JScrollPane Into Jpanel With Null Layout?"* That's like asking *"What's the most efficient way to fly a pig?"*. 1) 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). 2) Provide ASCII art or a simple drawing of the *intended* layout of the GUI .. – Andrew Thompson Jun 02 '17 at 13:23
  • .. at minimum size, and if resizable, with more width and height. 3) Voting to close as 'too broad', given the title effectively rules out the only sensible approach. – Andrew Thompson Jun 02 '17 at 13:23
  • `How To Add JScrollPane Into Jpanel With Null Layout?` - If your panel uses a null layout then the scrollpane won't work. The scrollbars only appear when the "preferred size" of the panel is greater that the size of the scroll pane. One of the jobs of a layout manager is to dynamically calculate the preferred size of the panel. – camickr Jun 02 '17 at 14:28
  • So how can I fix this problem – Mohammad Azaz Jun 02 '17 at 14:44

1 Answers1

0

I have found my Answer instead of using absolute layout I preferred to use GroupLayout because in this we can layout component to its absolute position in JPanel and we can also add JScrollPane to the JPanel Easily.