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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:19:49+00:00 2026-05-15T20:19:49+00:00

I have declared an ArrayList and DefaultListModel DefaultListModel model; List<AddFlight> Flights = new ArrayList<AddFlight>();

  • 0

I have declared an ArrayList and DefaultListModel

DefaultListModel model;

List<AddFlight> Flights = new ArrayList<AddFlight>();

To this list I add an object as an element

Flights.add(new AddFlight(txtFlightNo.getText(),
            (String)cmbMechanicalStatus.getSelectedItem(),
            (String)cmbMedicalStatus.getSelectedItem(),
            Float.valueOf((txtFuelLevel.getText()).trim()).floatValue(),
            (String)cmbWeatherCondition.getSelectedItem(),
            (String)cmbFrequency.getSelectedItem()));

In the action Performed (ActionEvent e) I want to print each object in one line in a understandable way on the JScrollPane.

model.add(0,Flights);

My output looks like this [When I add 2 objects to the ArrayList]:

alt text

WHAT I WANT:

1) I want each object in the ArrayList to appear in one line.

2) And I want it to appear like this in the JScrollPane:


Flight No: UL209, Mechanical Status:OK, Medical Status : Failure,Fuel Level : 12.0 //Line one

Flight No: UL210, Mechanical Status:OK, Medical Status : OK,Fuel Level : 22.0 // Line two


However, I managed to print out each element using the code below :

   for (AddFlight Flight : Flights) {
        System.out.println("FLight No : " + Flight.getFlightNo());
        System.out.println("Mechanical Status : " + Flight.getMechanicalStatus());
        System.out.println("Medical Status : " + Flight.getMedicalStatus());
        System.out.println("Fuel Level : " + Flight.getFuelLevel());
        System.out.println("Weather Condition: " + Flight.getWeatherCondition());
        System.out.println("Frequency : " + Flight.getFrequency());

    }

MY FULL CODE


import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;
import javax.swing.DefaultListModel;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class Flight implements ActionListener {

//String array
String[] MechanicalStatus = {"Select", "Ok", "Failure"};
String[] MedicalStatus = {"Select", "Ok", "Failure"};
String[] WeatherCondition = {"Select", "Sunny", "Raining", "Thunder", "Hurricane"};
String[] Frequency = {"Will be AutoSet", "ATC 1", "ATC 2", "ATC 3"};
//JPanel
JPanel pnlInput = new JPanel(new GridLayout(7, 2, 20, 20));
//Add textfields here
JTextField txtFlightNo = new JTextField(8);
JComboBox cmbMechanicalStatus = new JComboBox(MechanicalStatus);
JComboBox cmbMedicalStatus = new JComboBox(MedicalStatus);
JTextField txtFuelLevel = new JTextField(8);
JComboBox cmbWeatherCondition = new JComboBox(WeatherCondition);
JComboBox cmbFrequency = new JComboBox(Frequency);
//Add labels here
JLabel lblFlightNo = new JLabel("Flight No : ");
JLabel lblMechanicalStatus = new JLabel("Mechanical Status : ");
JLabel lblMedicalStatus = new JLabel("Medical Status : ");
JLabel lblFuelLevel = new JLabel("Fuel Level (gallons) : ");
JLabel lblWeatherCondition = new JLabel("Weather Condition :");
JLabel lblFrequency = new JLabel("Frequency : ");
List<AddFlight> Flights = new ArrayList<AddFlight>();
DefaultListModel model;

public Flight(DefaultListModel model) {

    this.model = model;

    //Adding flightno to panel
    pnlInput.add(lblFlightNo);
    pnlInput.add(txtFlightNo);

    //Adding mechanicalstatus to the panel
    pnlInput.add(lblMechanicalStatus);
    pnlInput.add(cmbMechanicalStatus);

    //Adding medicalstatus to the panel
    pnlInput.add(lblMedicalStatus);
    pnlInput.add(cmbMedicalStatus);

    //Adding fuellevel to the panel
    pnlInput.add(lblFuelLevel);
    pnlInput.add(txtFuelLevel);

    //Adding weathercondition to the panel
    pnlInput.add(lblWeatherCondition);
    pnlInput.add(cmbWeatherCondition);

    //Adding frequency to the panel
    pnlInput.add(lblFrequency);
    pnlInput.add(cmbFrequency);
}

public void actionPerformed(ActionEvent e) {
    int result = JOptionPane.showConfirmDialog(null, pnlInput, "Flight Details",
            JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);

    if (result == JOptionPane.OK_OPTION) {
        System.out.println("Plane [" + txtFlightNo.getText() + "] has arrived at the airport.\n");
        System.out.println("Mechanical status " + cmbMechanicalStatus.getSelectedItem() + "\n");
    }



    Flights.add(new AddFlight(txtFlightNo.getText(),
            (String) cmbMechanicalStatus.getSelectedItem(),
            (String) cmbMedicalStatus.getSelectedItem(),
            Float.valueOf((txtFuelLevel.getText()).trim()).floatValue(),
            (String) cmbWeatherCondition.getSelectedItem(),
            (String) cmbFrequency.getSelectedItem()));

    //persons.add(new AddFlight("UL210", "FAILURE", "OK", 90, "Rainy", "ATC 2"));


    for (AddFlight Flight : Flights) {
        System.out.println("FLight No : " + Flight.getFlightNo());
        System.out.println("Mechanical Status : " + Flight.getMechanicalStatus());
        System.out.println("Medical Status : " + Flight.getMedicalStatus());
        System.out.println("Fuel Level : " + Flight.getFuelLevel());
        System.out.println("Weather Condition: " + Flight.getWeatherCondition());
        System.out.println("Frequency : " + Flight.getFrequency());

    }

    model.add(0, Flights);
}
}

Any Help is appreciated…

  • 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-05-15T20:19:50+00:00Added an answer on May 15, 2026 at 8:19 pm

    You’re displaying your list twice in your control. Additionally, if you want to display relevant information rather than simply the object type and memory address, you need to define a toString method:

    public String toString()
    {
        return "Flight No: " + flightNo + ", Mechanical Status:" + mechStatus + ", Medical Status : " + medStatus + ",Fuel Level : " + fuel;
    }
    

    EDIT:

    It looks like, in order to display each AddFlight object on one line, you should be using

    model.add(0, Flights.get(Flights.size() - 1));
    

    (Add each AddFlight object to your model individually)

    Instead of

    model.add(0,Flights);
    

    (Adding the entire ArrayList to your model each time you add a new element)

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

Sidebar

Ask A Question

Stats

  • Questions 511k
  • Answers 511k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The mysql mathematical expression parser is quite fast since it… May 16, 2026 at 5:17 pm
  • Editorial Team
    Editorial Team added an answer You're on the right track. Google's OP Identifier (which is… May 16, 2026 at 5:17 pm
  • Editorial Team
    Editorial Team added an answer This is almost always caused by a combination of an… May 16, 2026 at 5:17 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have a Java question about generics. I declared a generic list: List<? extends
Please have a look at following code : import java.util.ArrayList; import java.util.List; class Main{
I have a collection of strings and declared the strings individually as arrays using
I am new to java, I have seen in the code at many places
I have a heavily populated arraylist, which I want to clear and reuse. If
In my C# project I have a static List that gets filled immediately when
We have a pojo that needs to have a list of integers. As an
In my Java application i need to compare two list's element whether it is
I have some object, say son , which I'd like to inherit from another
i have function which is something like this function multiple_delete($entity1,$entity2,$entity2) { $query = SELECT

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.