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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:01:02+00:00 2026-06-04T19:01:02+00:00

I’ve been trying to sort this out for a while now, I have checked

  • 0

I’ve been trying to sort this out for a while now, I have checked the docs (if you notice the table code is from there), and I just can’t quite figure it out. Am I using the wrong containers or do I need to dimension it? If so, how?

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class Invest extends JFrame {

    public static void main(String[] args) {
        demolayout frame = new demolayout();
        frame.setTitle("Financial Calculator");

        JPanel toppanel = new JPanel(new GridLayout(3, 3, 2, 2));
        frame.add(toppanel, BorderLayout.NORTH);

        String[] columnNames = {"Entry", "Year", "Year", "Year", "Year"};

        Object[][] data = {{"Period Ending:", "2011", "Snowboarding", new Integer(5), new Boolean(false)},
            {"Values in Millions of $", "12-31", "Rowing", new Integer(3), new Boolean(true)},
            {"Revenue:", "46,542", "Knitting", new Integer(2), new Boolean(false)},
            {"Revenue Other:", "-", "Speed reading", new Integer(20), new Boolean(true)},
            {"Total Revenue:", "46,542", "Speed reading", new Integer(20), new Boolean(true)},
            {"Cost of Revenue:", "18,216", "Speed reading", new Integer(20), new Boolean(true)},
            {"Gross Profit:", "28,326", "Speed reading", new Integer(20), new Boolean(true)},
            {"Selling Gen. Admin Expenses:", "12,111", "Speed reading", new Integer(20), new Boolean(true)},
            {"Research & Development:", "-", "Speed reading", new Integer(20), new Boolean(true)},
            {"Depreciation/Amortization:", "-", "Speed reading", new Integer(20), new Boolean(true)},
            {"Total Operating Expense:", "154", "Speed reading", new Integer(20), new Boolean(true)},
            {"Operating Income:", "35,810", "Speed reading", new Integer(20), new Boolean(true)},
            {"Interest Income (Exp.), Net NonOp:", "10,732", "Speed reading", new Integer(20), new Boolean(true)},
            {"Interest/Invest Inc. Non-Operating:", "White", "Speed reading", new Integer(20), new Boolean(true)},
            {"Interest Inc. Net Non-Operating:", "White", "Speed reading", new Integer(20), new Boolean(true)},
            {"Gain/Loss on Sale of Assets:", "White", "Speed reading", new Integer(20), new Boolean(true)},
            {"Other, Net:", "White", "Speed reading", new Integer(20), new Boolean(true)},
            {"Net Income Before Taxes:", "White", "Speed reading", new Integer(20), new Boolean(true)},
            {"Income Tax - Total:", "White", "Speed reading", new Integer(20), new Boolean(true)},
            {"Minority Interest:", "Brown", "Pool", new Integer(10), new Boolean(false)},
            {"Equity In Affiliates:", "Brown", "Pool", new Integer(10), new Boolean(false)},
            {"Accounting Change:", "Brown", "Pool", new Integer(10), new Boolean(false)},
            {"Discontinued Operations:", "Brown", "Pool", new Integer(10), new Boolean(false)},
            {"Extraordinary Items:", "Brown", "Pool", new Integer(10), new Boolean(false)},
            {"Net Income:", "Brown", "Pool", new Integer(10), new Boolean(false)}};

        JTable table = new JTable(data, columnNames);
        JScrollPane scrollPane = new JScrollPane(table);
        toppanel.add(scrollPane);

        JPanel bottompanel = new JPanel(new FlowLayout());
        bottompanel.setBackground(new Color(150, 150, 150));

        JButton compute = new JButton("Compute Ratios");
        bottompanel.add(compute);
        frame.add(bottompanel, BorderLayout.SOUTH);


        frame.setSize(800, 500);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }
}

enter image description here

  • 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-04T19:01:03+00:00Added an answer on June 4, 2026 at 7:01 pm

    Looks good added to the frame’s BorderLayout.CENTER.

    Also, don’t create new objects if there’s an existing primitive or factory method.

    Addendum: What do you mean factory method?

    Good question; Integer. valueOf() is a typical static factory method. As indicated in the API and discussed in Joshua Bloch’s Item 1: Consider static factory methods instead of constructors, the method caches frequently requested values.

    table

    import java.awt.*;
    import javax.swing.*;
    
    public class Invest extends JFrame {
    
        public static void main(String[] args) {
            JFrame frame = new JFrame();
            frame.setTitle("Financial Calculator");
    
            JPanel toppanel = new JPanel(new GridLayout(3, 3, 2, 2));
            frame.add(toppanel, BorderLayout.NORTH);
    
            String[] columnNames = {"Entry", "Year", "Year", "Year", "Year"};
    
            Object[][] data = {{"Period Ending:", "2011", "Snowboarding", Integer.valueOf(5), false},
                {"Values in Millions of $", "12-31", "Rowing", Integer.valueOf(3), true},
                {"Revenue:", "46,542", "Knitting", Integer.valueOf(2), false},
                {"Revenue Other:", "-", "Speed reading", Integer.valueOf(20), true},
                {"Total Revenue:", "46,542", "Speed reading", Integer.valueOf(20), true},
                {"Cost of Revenue:", "18,216", "Speed reading", Integer.valueOf(20), true},
                {"Gross Profit:", "28,326", "Speed reading", Integer.valueOf(20), true},
                {"Selling Gen. Admin Expenses:", "12,111", "Speed reading", Integer.valueOf(20), true},
                {"Research & Development:", "-", "Speed reading", Integer.valueOf(20), true},
                {"Depreciation/Amortization:", "-", "Speed reading", Integer.valueOf(20), true},
                {"Total Operating Expense:", "154", "Speed reading", Integer.valueOf(20), true},
                {"Operating Income:", "35,810", "Speed reading", Integer.valueOf(20), true},
                {"Interest Income (Exp.), Net NonOp:", "10,732", "Speed reading", Integer.valueOf(20), true},
                {"Interest/Invest Inc. Non-Operating:", "White", "Speed reading", Integer.valueOf(20), true},
                {"Interest Inc. Net Non-Operating:", "White", "Speed reading", Integer.valueOf(20), true},
                {"Gain/Loss on Sale of Assets:", "White", "Speed reading", Integer.valueOf(20), true},
                {"Other, Net:", "White", "Speed reading", Integer.valueOf(20), true},
                {"Net Income Before Taxes:", "White", "Speed reading", Integer.valueOf(20), true},
                {"Income Tax - Total:", "White", "Speed reading", Integer.valueOf(20), true},
                {"Minority Interest:", "Brown", "Pool", Integer.valueOf(10), false},
                {"Equity In Affiliates:", "Brown", "Pool", Integer.valueOf(10), false},
                {"Accounting Change:", "Brown", "Pool", Integer.valueOf(10), false},
                {"Discontinued Operations:", "Brown", "Pool", Integer.valueOf(10), false},
                {"Extraordinary Items:", "Brown", "Pool", Integer.valueOf(10), false},
                {"Net Income:", "Brown", "Pool", Integer.valueOf(10), false}};
    
            JTable table = new JTable(data, columnNames);
            JScrollPane scrollPane = new JScrollPane(table);
            frame.add(scrollPane, BorderLayout.CENTER);
    
            JPanel bottompanel = new JPanel(new FlowLayout());
            bottompanel.setBackground(new Color(150, 150, 150));
    
            JButton compute = new JButton("Compute Ratios");
            bottompanel.add(compute);
            frame.add(bottompanel, BorderLayout.SOUTH);
    
            frame.pack();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
Does anyone know how can I replace this 2 symbol below from the string

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.