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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T01:31:14+00:00 2026-06-03T01:31:14+00:00

I cannot set my new windows layout. I have a menu and submenus. I

  • 0

I cannot set my new windows layout. I have a menu and submenus. I have an action listener on my submenu which directs me to new window. The problem is I cannot set it to given layout. Here’s my code:

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

public class Converter extends JFrame
{
    private static final long serialVersionUID = 1L;
    private MoneyDetails convertMe = new MoneyDetails();
    private JLabel tlLabel = new JLabel("     Amount of TL");
    private JLabel dollarsLabel = new JLabel("Amount of Dollars");
    private JTextField tlField = new JTextField("0.0");
    private JTextField dollarsField = new JTextField("0.0");
    private JButton tlButton = new JButton("Convert to $");
    private JButton dollarsButton = new JButton("<<< Convert to TL");
    private JButton setRates = new JButton("Set Rates");

    private JMenuBar menuBar = new JMenuBar(); // Window menu bar
    public Converter(String title) {
        setTitle(title);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setJMenuBar(menuBar); // Add the menu bar to the window
        JMenu fileMenu = new JMenu("File"); // Create File menu
        JMenu elementMenu = new JMenu("Elements"); // Create Elements menu
        JMenuItem subTest = new JMenuItem("Test");

        // Here is the problem
        subTest.addActionListener(new ActionListener(){     
            public void actionPerformed(ActionEvent actionEvent){
                Converter convert = new Converter();

                GridLayout expLay = new GridLayout(2,2,12,6);
                convert.setLayout(expLay);
                convert.getLayout();
                convert.doLayout();
                convert.setVisible(true);
            }
        });

        menuBar.add(fileMenu); // Add the file menu
        menuBar.add(elementMenu); // Add the element menu
        fileMenu.add(subTest);
    }

    public Converter()
    {
        JPanel dataPanel = new JPanel(new GridLayout(2, 2, 12, 6));
        dataPanel.add(tlLabel);

        dataPanel.add(dollarsLabel);
        dataPanel.add(tlField);
        dataPanel.add(dollarsField);
        JPanel buttonPanel = new JPanel();
        buttonPanel.add(tlButton);
        buttonPanel.add(dollarsButton);
        Container container = this.getContentPane();
        container.add(dataPanel, BorderLayout.CENTER);
        container.add(buttonPanel, BorderLayout.SOUTH);
        tlButton.addActionListener(new TLConverter());
        dollarsButton.addActionListener(new DollarsConverter());
        buttonPanel.add(setRates);
    }

    private class TLConverter implements ActionListener
    {
        public void actionPerformed(ActionEvent e)
        {
            try
            {
                String input = tlField.getText();
                double tl = Double.parseDouble(input);
                convertMe.setTL(tl);
                double dollars = convertMe.getDollars();
                dollarsField.setText(String.format("%.2f", dollars));
            }
            catch(Exception ex)
            {
                JOptionPane.showMessageDialog(null, "Please enter the amount that will be converted.");
            }
        }
    }

    private class DollarsConverter implements ActionListener
    {
        public void actionPerformed(ActionEvent e)
        {
            String input = dollarsField.getText();
            double dollars = Double.parseDouble(input);
            convertMe.setDollars(dollars);
            double tl = convertMe.getTL();
            tlField.setText(String.format("%.2f", tl));
        }
    }

    public static void main(String [] args)
    {
        System.out.println("bbb");
        Converter window = new Converter("Para Dönüstürücü"); 
        System.out.println("aaa");
        window.setBounds(30, 30, 300, 300);
        window.setVisible(true);
    /*  Converter theGUI = new Converter();
        theGUI.setTitle("TL to $ or $ to TL Converter");
        theGUI.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        theGUI.pack();
        theGUI.setVisible(true); */
    }
}

Problem lies in the constructor with a String argument: subTest.addActionListener(new ActionListener(){...

  • 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-03T01:31:16+00:00Added an answer on June 3, 2026 at 1:31 am

    Add a call to pack() in the default constructor.

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

Sidebar

Related Questions

i have written a generic repository for my base windows which have a problem
I've read articles that Child Windows in SL3 cannot be set to non-moveable, without
Im new to data binding in Windows Phone 7 and cannot get this code
Edit2: See below for new problem. I'm creating a Windows Phone 7 game and
Problem Users from other IPs on the (Windows XP) LAN suddenly cannot connect to
I cannot set title_for_layout in the PagesController that comes by default with CakePHP 1.3.
I cannot get/set a static variable inside a method. How can I do it?
I know that you cannot simply set DocumentRoot in htaccess but it's all I
I cannot get the DropDownHeight of the ComboBox set properly to display all the
I cannot figure out how to set an estimated maximum price for a collection

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.