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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:46:26+00:00 2026-06-17T09:46:26+00:00

So basicly I’m a little confused here, I’m using WindowsPro Builder plugin for eclipse,

  • 0

So basicly I’m a little confused here, I’m using WindowsPro Builder plugin for eclipse, and it makes all the JFrame components in a custom initialize () class. This creates a question for me, normally I define my components in the beginning so I can access them publicly trough my program. No I have a second class, but i cant access my components. For example I cant figure out how to make a unified ActionListener for the whole initialize class.

I also want to get the input from the textarea, but how can I do so? When everything is outside the scope? As you can se i call the class SaveToFile, in that class i want to get the input from the textarea, but how would i do this?

 import javax.swing.*;


 public class FunctionsGUI  {

private JFrame frame;

/**
 * Launch the application.
 */
public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            try {
                FunctionsGUI window = new FunctionsGUI();
                window.frame.setVisible(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}

/**
 * Create the application.
 */
public FunctionsGUI() {
    initialize();

}

/**
 * Initialize the contents of the frame.
 */
private void initialize ()   {

    try {
          UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch(Exception e) {
          System.out.println("Error setting native LAF: " + e);
        }

    frame = new JFrame();
    frame.setBounds(100, 100, 571, 531);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    SpringLayout springLayout = new SpringLayout();
    frame.getContentPane().setLayout(springLayout);

    JTextPane textPane = new JTextPane();
    springLayout.putConstraint(SpringLayout.NORTH, textPane, 10, SpringLayout.NORTH, frame.getContentPane());
    springLayout.putConstraint(SpringLayout.WEST, textPane, 10, SpringLayout.WEST, frame.getContentPane());
    springLayout.putConstraint(SpringLayout.SOUTH, textPane, 462, SpringLayout.NORTH, frame.getContentPane());
    springLayout.putConstraint(SpringLayout.EAST, textPane, 545, SpringLayout.WEST, frame.getContentPane());
    frame.getContentPane().add(textPane);
    frame.setLocationRelativeTo(null);
    frame.setTitle("Calcolo");


    JMenuBar menuBar = new JMenuBar();
    frame.setJMenuBar(menuBar);

    JMenu mnFile = new JMenu("File");
    menuBar.add(mnFile);

    final JMenuItem mntmSave = new JMenuItem("Save");
    mntmSave.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            SaveToFile sv = new SaveToFile();
        }
    });
    mnFile.add(mntmSave);

    JMenu mnOptions = new JMenu("Options");
    menuBar.add(mnOptions);

    JMenu mnHelp = new JMenu("Help");
    menuBar.add(mnHelp);

    final JMenuItem AboutMenu = new JMenuItem("About");
    AboutMenu.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            if (e.getSource().equals(AboutMenu)) {
                 JDialog dialog = new JDialog();
                    dialog.setTitle("Search Dialog");
                    dialog.getContentPane().add(new JLabel("Just a test"));
                    dialog.setSize(300,300);
                    dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
                    dialog.setLocationRelativeTo(frame);
                    dialog.setVisible(true);

            if (e.getSource().equals(mntmSave));
                SaveToFile sv = new SaveToFile ();
            }
        }
    });
    mnHelp.add(AboutMenu);

}
}
  • 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-17T09:46:27+00:00Added an answer on June 17, 2026 at 9:46 am

    I would like to show you a way. Have a constructor in SaveToFile class which can accept String as below. Pass the text from you textpane to this constructor or method as String. Or even a method is good. But have any one of these two.

    public class SaveToFile {
    
        public SaveToFile(String textinput) {
            System.out.println(textinput);
        }
    
        // if you prefer to have a differrent method do like below.
    
        public void doSomething(String textinput) {
                System.out.println(textinput);
        }
    }
    

    Now change your listener to like like below,

    final JMenuItem mntmSave = new JMenuItem("Save");
        mntmSave.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                SaveToFile sv = new SaveToFile(textPane.getText());
            }
    });
    

    If you don’t want a constructor then,

    final JMenuItem mntmSave = new JMenuItem("Save");
            mntmSave.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                      SaveToFile sv = new SaveToFile();
                      sv.doSomething(textPane.getText());
                }
    });
    

    What I am doing is I’m sending a text from the textpanel to the SaveToFile class. There you can use this String. Make sure that you declare JTextPane as final like below

    final JTextPane textPane = new JTextPane();
    

    Now you got a text from textpane whcih is in another class to SaveToFile class. As I said its just “A Way not THE way”.

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

Sidebar

Related Questions

I need to develop an app that is using multithreading. Basicly, I have a
Ok, basicly, I made a script (that one) that makes a .post to a
I'm using a function to fetch data from webapi. Basicly using $.ajax . I'm
I am using Navigation framework and basicly got one frame that is used for
Hi basicly i am trying to use the svm from here . It is
I have this static function which basicly makes a connection to a webpage, send
I'm basicly trying to make my class able to iterate using foreach . I
What I've got is basicly two classes Plugin and PluginLauncher Plugin is an abstract
Basicly i've got this setup | JFrame with BorderLayout | | -------------------------- | |
Here is my code: http://jsfiddle.net/sZKeM/1/ So basicly it shows box when I hover button

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.