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 9169985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:57:15+00:00 2026-06-17T15:57:15+00:00

I tried to do a search system using java swing : public void search(ActionEvent

  • 0

I tried to do a search system using java swing :

    public void search(ActionEvent e){
    String textEntered=getJTextField_searchField().getText();
    if(textEntered.equals("")){
        JOptionPane.showMessageDialog(null,"Please enter a word");
    }
    else{
        kioskViewevents viewEvents=new kioskViewevents(textEntered);
        if(viewEvents.searchContent() == true){
            getJScrollPane().setVisible(false);
            getJScrollPane_search();
        }
        else{
            JOptionPane.showMessageDialog(null,"No result found");
        }


    }
}

This method will be perform after search button is on click. It will hide the previous table then replace with another table. Then I populate the search results inside the table.

    public void SetUpJTable_search(){
    DefaultTableModel tableModel = (DefaultTableModel) jTableSearch.getModel();

    String[] data = new String[5];
    db.setUp("IT Innovation Project");
    String sql = "Select event_ID,event_Price,event_Title,event_Time,event_Date FROM crossEvent WHERE event_Title='"+ textEntered +"'";

    ResultSet resultSet = null;
    resultSet = db.readRequest(sql);
    try {
        while (resultSet.next()) {
            data[0] = resultSet.getString("event_ID");
            data[1] = resultSet.getString("event_Price");
            data[2] = resultSet.getString("event_Title");
            data[3] = resultSet.getString("event_Time");
            data[4] = resultSet.getString("event_Date");
            tableModel.addRow(data);
        }
        resultSet.close();
    } catch (Exception e) {
        System.out.println(e);
    }

}

I set up my Search table :

    private JTable getJTable_search() {
    String header[] = { "Event ID", "Price", "Title","Time","Date"};
    DefaultTableModel tableModel = (DefaultTableModel) jTable.getModel();
    tableModel.setColumnIdentifiers(header);
    jTableSearch.setAutoCreateColumnsFromModel(false);
    jTableSearch.getColumnModel().getColumn(0).setMinWidth(100);
    jTableSearch.getColumnModel().getColumn(0).setMaxWidth(100);

    jTableSearch.getColumnModel().getColumn(1).setMinWidth(200);
    jTableSearch.getColumnModel().getColumn(1).setMaxWidth(300);

    jTableSearch.getColumnModel().getColumn(2).setMinWidth(300);
    jTableSearch.getColumnModel().getColumn(2).setMaxWidth(400);

    jTableSearch.getColumnModel().getColumn(3).setMinWidth(100);
    jTableSearch.getColumnModel().getColumn(3).setMaxWidth(100);

    jTableSearch.getColumnModel().getColumn(4).setMinWidth(100);
    jTableSearch.getColumnModel().getColumn(4).setMaxWidth(100);


    jTableSearch.getTableHeader().setFont(new Font("Dialog", Font.PLAIN, 20));
    jTableSearch.getTableHeader().setForeground(Color.white);
    jTableSearch.getTableHeader().setBackground(new Color(102, 102, 102));
    jTableSearch.setRowHeight(50);
    jTableSearch.setBounds(new Rectangle(97, 157, 800, 450));
    jTableSearch.setFont(new Font("Dialog", Font.PLAIN, 18));

    return jTableSearch;
}

My Scroll Pane for search table :

    private JScrollPane getJScrollPane_search(){
    if (jScrollPane_search == null) {
        jScrollPane_search = new JScrollPane();
        jScrollPane_search.setBounds(new Rectangle(75, 180, 800, 450));
        jScrollPane_search.setViewportView(getJTable_search());
    }
    SetUpJTable_search();
    return jScrollPane_search;
}

This whole junk of codes is to populate the table with data existing in database before performing search :

    private JTable getJTable() {
    String header[] = { "Event ID", "Price", "Title","Time","Date"};
    DefaultTableModel tableModel = (DefaultTableModel) jTable.getModel();
    tableModel.setColumnIdentifiers(header);
    // Hide Topic ID
    jTable.setAutoCreateColumnsFromModel(false);
    jTable.getColumnModel().getColumn(0).setMinWidth(100);
    jTable.getColumnModel().getColumn(0).setMaxWidth(100);

    jTable.getColumnModel().getColumn(1).setMinWidth(200);
    jTable.getColumnModel().getColumn(1).setMaxWidth(300);

    jTable.getColumnModel().getColumn(2).setMinWidth(300);
    jTable.getColumnModel().getColumn(2).setMaxWidth(400);

    jTable.getColumnModel().getColumn(3).setMinWidth(100);
    jTable.getColumnModel().getColumn(3).setMaxWidth(100);

    jTable.getColumnModel().getColumn(4).setMinWidth(100);
    jTable.getColumnModel().getColumn(4).setMaxWidth(100);

    jTable.getTableHeader().setFont(new Font("Dialog", Font.PLAIN, 20));
    jTable.getTableHeader().setForeground(Color.white);
    jTable.getTableHeader().setBackground(new Color(102, 102, 102));
    jTable.setRowHeight(50);
    jTable.setBounds(new Rectangle(97, 157, 800, 450));
    jTable.setFont(new Font("Dialog", Font.PLAIN, 18));

    return jTable;
}

    public void SetUpJTable() {
    DefaultTableModel tableModel = (DefaultTableModel) jTable.getModel();

    String[] data = new String[5];
    db.setUp("IT Innovation Project");
    String sql = "Select event_ID,event_Price,event_Title,event_Time,event_Date FROM crossEvent";

    ResultSet resultSet = null;

    resultSet = db.readRequest(sql);
    tableModel.getDataVector().removeAllElements();
    tableModel.fireTableDataChanged();
    try {
        while (resultSet.next()) {
            data[0] = resultSet.getString("event_ID");
            data[1] = resultSet.getString("event_Price");
            data[2] = resultSet.getString("event_Title");
            data[3] = resultSet.getString("event_Time");
            data[4] = resultSet.getString("event_Date");

            tableModel.addRow(data);
        }
        resultSet.close();
    } catch (Exception e) {
        System.out.println(e);
    }
}

However, I got an error message which is :

    Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 0 >= 0
at java.util.Vector.elementAt(Unknown Source)
at javax.swing.table.DefaultTableColumnModel.getColumn(Unknown Source)
at kioskViewevents.ui.ViewEventsUI.getJTable_search(ViewEventsUI.java:158)
at kioskViewevents.ui.ViewEventsUI.getJScrollPane_search(ViewEventsUI.java:201)
at kioskViewevents.ui.ViewEventsUI.search(ViewEventsUI.java:330)
at kioskViewevents.ui.ViewEventsUI$4.actionPerformed(ViewEventsUI.java:315)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$400(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

Any guides? Thanks in advance.

  • 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-17T15:57:16+00:00Added an answer on June 17, 2026 at 3:57 pm

    Not sure which one is the line 158 in ViewEvents.java (as you haven’t mentioned it), but the stacktrace and remaining code tells me that the ArrayIndexOutOfBounds exception is because you’re trying to access a column like below:

        jTable.getColumnModel().getColumn(4).setMaxWidth(100);  // Not sure which column is the issue
    

    And you don’t have those many columns in the vector i.e. jTable.getColumnModel(). You’re trying to access an element beyond the size of the vector.

    The exact problem on why/where this issue occurs could be different, but this is where you should start looking at.

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

Sidebar

Related Questions

using System; public delegate void Printer(string s); class Program { public static void Main(string[]
I am developing an Online Recruitment System in Java EE using Servlets and I
Tried to search for this online and didn't get very far, so I'm asking
tried to search for this, although I am not even sure what I am
I tried to search 2 days about how to do the paging scroll in
I tried to search for what is git commit consists of and what parts
I tried to search SO but couldn't find close answers. What I have is
i tried to search this but was not able to get any proper help.I
I tried to search for a JavaScript reference, but there's none available. The best
I tried to search and found this: Sort an array by a child array's

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.