Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8851257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:06:40+00:00 2026-06-14T13:06:40+00:00

The program consists of a tabbed view with a few JTextField ‘s and JButton

  • 0

The program consists of a tabbed view with a few JTextField‘s and JButtons in the first two and 2 JTables and JButton in the third. The buttons work fine in the first two tabs, but on the third it is un-clickable. I tried changing the button to something else like a JComboBox or JTextField but those are uneditable and unclickable also. Setting the setEnabled() and setEditable() functions to true doesn’t seem to work. I have no idea what’s going on.

The only thing i have done different from normal is this piece of code to forcefully repaint the tab when I click on a cell in the table. But even when this hasn’t been called i still cant

ContentIWantToRepaint.this.paintImmediately(ContentIWantToRepaint.this.getVisibleRect());

Some other information about the layout:
The contents of the tab are held in a JPanel with a GridBagLayout

  • JTextField
  • Table Header
  • Table Contents
  • JTextField
  • Table Header
  • Table Contents
  • Button

Any suggestions?

checkOutPanel.java

import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.Vector;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.ScrollPaneConstants;
import javax.swing.table.DefaultTableModel;


public class checkOutPanel extends JPanel {
    private JTable userTable;
    private JTable bookTable;
    private JScrollPane scrollUserTable, scrollBookTable;
    private JLabel userLabel, bookLabel;
    private DefaultTableModel userTableModel = new DefaultTableModel(){
        public boolean isCellEditable(int row, int column){return false;}
    };
    private DefaultTableModel bookTableModel = new DefaultTableModel(){
        public boolean isCellEditable(int row, int column){return false;}
    };
    private int selectedUser, selectedBook;
    private JComboBox date_month, date_day, date_year;

    public checkOutPanel(){

        JPanel mainGrid = new JPanel();//panel that will hold all stuff in tab
        JPanel buttonPanel = new JPanel();//panel for holding buttons

        mainGrid.setLayout(new GridBagLayout());
        GridBagConstraints c = new GridBagConstraints();
        c.gridx=0; c.gridy=0; //first row first column
        c.anchor = GridBagConstraints.WEST;//align left
        c.fill = GridBagConstraints.HORIZONTAL;

        //1 row, 2 columns, 15 horizontal padding, 0 vertical padding
        //buttonPanel.setLayout(new GridLayout(1,2,15,0));

        //labels to describe what the user has to do
        userLabel = new JLabel("User :");
        bookLabel = new JLabel("Book :");
        JLabel dateLabel = new JLabel("Date :");
        JPanel datePanel = new JPanel();

        bookTable = new JTable(bookTableModel);
        bookTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        userTable = new JTable(userTableModel);
        userTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        Dimension d = new Dimension(500, 120);

        scrollBookTable = new JScrollPane(bookTable); 
        scrollBookTable.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS); 
        scrollBookTable.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); 
        scrollBookTable.setMaximumSize(d);
        scrollBookTable.setMinimumSize(d);
        scrollBookTable.setPreferredSize(d);

        scrollUserTable = new JScrollPane(userTable); 
        scrollUserTable.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS); 
        scrollUserTable.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); 
        scrollUserTable.setMaximumSize(d);
        scrollUserTable.setMinimumSize(d);
        scrollUserTable.setPreferredSize(d);

        updateTables();

        //String[] month = {"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};       

        //Vector<Integer> days = new Vector<Integer>();
        //for (int i=1 ; i<=31 ; i++) { days.add(i); }

        //Vector<Integer> years = new Vector<Integer>();
        //for (int i=2012 ; i>=1900 ; i--) { years.add(i); }

        //date_month = new JComboBox(days);
        JButton testButton = new JButton("WORK!!!!!!!");
        //date_day = new JTextField(6);
        //date_year = new JTextField(6);

        //datePanel.add(dateLabel);
        //datePanel.add(date_month);
        //datePanel.add(date_day);
        //datePanel.add(date_year);



        mainGrid.add(userLabel, c);                     c.gridy++;
        mainGrid.add(userTable.getTableHeader(), c);    c.gridy++;
        mainGrid.add(scrollUserTable, c);               c.gridy++;
        c.insets = new Insets(15, 0, 0, 0);//put some padding between users and books
        mainGrid.add(bookLabel, c);                     c.gridy++;
        c.insets= new Insets(0,0,0,0);//back to no padding
        mainGrid.add(bookTable.getTableHeader(), c);    c.gridy++;
        mainGrid.add(scrollBookTable, c);               c.gridy++;
        c.insets = new Insets(15, 0, 0, 0);//put some padding between books and date

        mainGrid.add(testButton, c);                        c.gridy++;





        this.add(mainGrid);//add contents to tab


        userTable.addMouseListener(new mouseListener());
        bookTable.addMouseListener(new mouseListener());

    }

    public class mouseListener implements MouseListener{
        @Override
        public void mouseClicked(MouseEvent e) {}
        @Override
        public void mouseEntered(MouseEvent e) {}
        @Override
        public void mouseExited(MouseEvent e) {}
        @Override
        public void mousePressed(MouseEvent e) {}
        @Override
        public void mouseReleased(MouseEvent e) {
            if(e.getSource()==userTable){
                selectedUser=userTable.getSelectedRow();
                userLabel.setText("User :  "+ (selectedUser!=-1 ? selectedUser : ""));

                //don't know why i should need to use this, but it makes it work
                checkOutPanel.this.paintImmediately(checkOutPanel.this.getVisibleRect());


            }else if(e.getSource()==bookTable){
                selectedBook = bookTable.getSelectedRow();
                System.out.println("Date Month : "+date_month.getSelectedItem().toString());
                bookLabel.setText("Book :  "+ (selectedBook!=-1 ? selectedBook : ""));

                //don't know why i should need to use this, but it makes it work
                checkOutPanel.this.paintImmediately(checkOutPanel.this.getVisibleRect());


            }
        }
    }





    private void updateTables(){
        bookTableModel.setDataVector(fillBookData(SystemStart.getDbName()), fillBookColNames());
        userTableModel.setDataVector(fillUserData(SystemStart.getDbName()), fillUserColNames());
    }




    private Vector<String> fillUserColNames(){
        Vector<String> colNames = new Vector<String>();
        colNames.add("ID");
        colNames.add("First");
        colNames.add("Last");
        colNames.add("Phone");
        colNames.add("Email");
        colNames.add("Address");
        colNames.add("City");
        colNames.add("State");
        colNames.add("Zip");        
        return colNames;
    }
    private Vector<String> fillBookColNames(){
        Vector<String> colNames = new Vector<String>();
        colNames.add("Title");
        colNames.add("Format");
        colNames.add("Author");
        colNames.add("ISBN");
        colNames.add("Year Pub.");
        colNames.add("Publisher");
        colNames.add("Call #");
        colNames.add("Copy #");     
        return colNames;    
    }
    private Vector<Vector<String>> fillUserData(String dbName){
        Vector<Vector<String>> v = new Vector<Vector<String>>();
        Vector<String> u;
        for (int i=0; i<10; i++){
            u = new Vector<String>(9);
            u.add(""+i);
            u.add("First");
            u.add("Last");
            u.add("Phone");
            u.add("Email");
            u.add("Address");
            u.add("City");
            u.add("State");
            u.add("Zip");
            v.add(u);
        }
        return v;
    }

    private Vector<Vector<String>> fillBookData(String dbName) {
        Vector<Vector<String>> v = new Vector<Vector<String>>();
        Vector<String> b;
        for (int i=0; i<10; i++){//only include books that arent check out
            b = new Vector<String>(8);
            b.add("Title "+i);
            b.add("Format");
            b.add("Author");
            b.add("ISBN");
            b.add("Year Pub.");
            b.add("Publisher");
            b.add("Call #");
            b.add("Copy #");
            v.add(b);
        }
        return v;
    }
}

Use this file to see how it doesn’t work:

import javax.swing.JFrame;

public class SystemStart{
    private static String dbName = "dbnamehere.db";

    public static void main(String[] args) {

        //new TabbedFrame("Libary System");
        JFrame jf = new JFrame("WORK!");
        jf.add(new checkOutPanel());
        jf.pack();
        jf.setVisible(true);
            jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

    public static String getDbName(){return dbName;}

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T13:06:41+00:00Added an answer on June 14, 2026 at 1:06 pm

    You’re adding to the panel a label, then the table’s header and then the scrollpane which contains the table (…and the table header). Remove the two lines where you’re adding to mainGrid the table headers (you should just add the scrollpanes):

        mainGrid.add(userTable.getTableHeader(), c);    c.gridy++;
        mainGrid.add(bookTable.getTableHeader(), c);    c.gridy++;
    

    Your button will work now.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a program which consists of two parts Service component will
I'm creating a small program which consists of a few source files on my
THIS IS HOMEWORK: I have a program that consists of two winforms and three
My program consists of 3 static buttons created using WinForms: button1, button2 and button3.
I have a very small c++ program that consists of two files: main.cpp and
I have a program that consists of two programs: Updater and WorkMaker. Whenever there
I have a program which consists of two simple Java Swing files. How do
So my program consists of two classes 1. My main class handling GUI which
A C++ program consists of two .cpp files, main.cpp and f.cpp. Code of the
I'm having trouble with the linking of my files. Basically, my program consists of:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.