Accessing controls in JFrame from parent.

  • (2 Pages)
  • +
  • 1
  • 2

15 Replies - 1391 Views - Last Post: 15 April 2012 - 07:58 PM Rate Topic: -----

#1 KClO3  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 16-March 12

Accessing controls in JFrame from parent.

Posted 15 April 2012 - 09:35 AM

Hi. I have a program with various JFrames controlled by a TabbedPane. I need to be able to access the controls on the JFrames, but I'm not sure how. I bet there's something about this on there internet somewhere, but I don't know how to word the question.

Anyway, here's what my program is like (in basic form):

Info.java
public class Info extends JFrame{

public static JTextField textField;

public Info(){
textField = new JTextField();
this.add(textField);
}
}



Main.java
public class Main{

private JFrame frmMainfrm;
JFrame info = new Info();

Initialize(){
TabbedPane tabControl = new TabbedPane();
tabControl.add(info);
frmMainfrm.add(tabControl);
}
}



My question is, is it possible to access textPane from Main.java without making a function that returns values? Even though it's public static variable, it doesn't show up like this:

info.textPane.getText();



Thanks for any help.

Is This A Good Question/Topic? 0
  • +

Replies To: Accessing controls in JFrame from parent.

#2 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5578
  • View blog
  • Posts: 11,918
  • Joined: 02-June 10

Re: Accessing controls in JFrame from parent.

Posted 15 April 2012 - 09:46 AM

1 info.textPane.getText();


for one, there is no textPane in your Info class. There is a textField in your Info class though. You need to use the right terms if you expect to reach it.

You have declared your Info() class to be public.
But you haven't declared TextField as public. I'm sure its the same in Java as my native C# that you have to specify every object as public if you want to see it from outside of the class it was made in. If you don't specify public, it is therefore private.
Was This Post Helpful? 0
  • +
  • -

#3 oha055  Icon User is offline

  • D.I.C Regular

Reputation: 49
  • View blog
  • Posts: 271
  • Joined: 02-February 09

Re: Accessing controls in JFrame from parent.

Posted 15 April 2012 - 09:50 AM

The right way to do this would be to create getter methods for all of the components you want to reach from outside of the class.

public JTextField getTextField() { return textField; }

This post has been edited by oha055: 15 April 2012 - 09:52 AM

Was This Post Helpful? 0
  • +
  • -

#4 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8342
  • View blog
  • Posts: 31,880
  • Joined: 06-March 08

Re: Accessing controls in JFrame from parent.

Posted 15 April 2012 - 09:52 AM

First I guess you talk about JTabbedPane when you write about TabbedPane
Second Initialize() has to be declared void and is not called by Main constructor
Third you can't put a JFrame into another JFrame so you can put a JFrame in a JTabbedPane
Fourth no reason for your JTextField to be static it is a bad design

Happy coding
Was This Post Helpful? 0
  • +
  • -

#5 KClO3  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 16-March 12

Re: Accessing controls in JFrame from parent.

Posted 15 April 2012 - 10:00 AM

View PosttlhIn`toq, on 15 April 2012 - 09:46 AM, said:

1 info.textPane.getText();


for one, there is no textPane in your Info class. There is a textField in your Info class though. You need to use the right terms if you expect to reach it.

You have declared your Info() class to be public.
But you haven't declared TextField as public. I'm sure its the same in Java as my native C# that you have to specify every object as public if you want to see it from outside of the class it was made in. If you don't specify public, it is therefore private.

Like I said, this is a mockup code example. It's not my actual program. I'll look at it again, I guess.

View Postpbl, on 15 April 2012 - 09:52 AM, said:

First I guess you talk about JTabbedPane when you write about TabbedPane
Second Initialize() has to be declared void and is not called by Main constructor
Third you can't put a JFrame into another JFrame so you can put a JFrame in a JTabbedPane
Fourth no reason for your JTextField to be static it is a bad design

Happy coding

I'm assuming that you meant you can't put a JFrame into a TabbedPane. I assure you, you can. I have it right here on my screen! :P.
Was This Post Helpful? 0
  • +
  • -

#6 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8342
  • View blog
  • Posts: 31,880
  • Joined: 06-March 08

Re: Accessing controls in JFrame from parent.

Posted 15 April 2012 - 10:00 AM

If the only reason of the existence of the Info class is to hold a JTextField and you want to access this JTextField from the Main class simply make it an inner class and declare the JTextField in the Main class

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

public class Main extends JFrame {

	JTextField textField;

	Main() {

		JTabbedPane tabControl = new JTabbedPane();
		tabControl.add(new Info());
		add(tabControl);
		setSize(400,400);
		setVisible(true);
		this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
	}
	
	public static void main(String[] args) {
		Main m = new Main();
	}
	
	class Info extends JPanel {
		Info() {
			textField = new JTextField("This is my textfield");
			add(textField);
		}
	}
}


Was This Post Helpful? 0
  • +
  • -

#7 KClO3  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 16-March 12

Re: Accessing controls in JFrame from parent.

Posted 15 April 2012 - 10:01 AM

View PostKClO3, on 15 April 2012 - 10:00 AM, said:

View PosttlhIn`toq, on 15 April 2012 - 09:46 AM, said:

1 info.textPane.getText();


for one, there is no textPane in your Info class. There is a textField in your Info class though. You need to use the right terms if you expect to reach it.

You have declared your Info() class to be public.
But you haven't declared TextField as public. I'm sure its the same in Java as my native C# that you have to specify every object as public if you want to see it from outside of the class it was made in. If you don't specify public, it is therefore private.

Like I said, this is a mockup code example. It's not my actual program. I'll look at it again, I guess.

View Postpbl, on 15 April 2012 - 09:52 AM, said:

First I guess you talk about JTabbedPane when you write about TabbedPane
Second Initialize() has to be declared void and is not called by Main constructor
Third you can't put a JFrame into another JFrame so you can put a JFrame in a JTabbedPane
Fourth no reason for your JTextField to be static it is a bad design

Happy coding

I'm assuming that you meant you can't put a JFrame into a TabbedPane. I assure you, you can. I have it right here on my screen! :P.

Also, I know that Initialize has to be void and called by Main and all that, this is just a quick example :P.
Was This Post Helpful? 0
  • +
  • -

#8 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8342
  • View blog
  • Posts: 31,880
  • Joined: 06-March 08

Re: Accessing controls in JFrame from parent.

Posted 15 April 2012 - 10:06 AM

View PostKClO3, on 15 April 2012 - 01:00 PM, said:

I'm assuming that you meant you can't put a JFrame into a TabbedPane. I assure you, you can. I have it right here on my screen! :P.

Post that code, I am anxious to see it :)

View PostKClO3, on 15 April 2012 - 01:01 PM, said:

Also, I know that Initialize has to be void and called by Main and all that, this is just a quick example :P.

And how are we supposed to distnguish between what you know and what is incorrect because you don't know ?
Better to post examples that work.
Was This Post Helpful? 1
  • +
  • -

#9 KClO3  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 16-March 12

Re: Accessing controls in JFrame from parent.

Posted 15 April 2012 - 10:14 AM

View Postpbl, on 15 April 2012 - 10:06 AM, said:

View PostKClO3, on 15 April 2012 - 01:00 PM, said:

I'm assuming that you meant you can't put a JFrame into a TabbedPane. I assure you, you can. I have it right here on my screen! :P.

Post that code, I am anxious to see it :)

View PostKClO3, on 15 April 2012 - 01:01 PM, said:

Also, I know that Initialize has to be void and called by Main and all that, this is just a quick example :P.

And how are we supposed to distnguish between what you know and what is incorrect because you don't know ?
Better to post examples that work.

Okay, here it is!

Main.java


import java.awt.Color;
import java.awt.EventQueue;

import javax.swing.DefaultComboBoxModel;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.UIManager;
import javax.swing.UIManager.LookAndFeelInfo;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.border.TitledBorder;

import java.awt.BorderLayout;

public class Main {

	private JFrame frmIdeb;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					try {
					    for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
					        if ("Nimbus".equals(info.getName())) {
					            UIManager.setLookAndFeel(info.getClassName());
					            break;
					        }
					    }
					} catch (UnsupportedLookAndFeelException e) {
					    // handle exception
					} catch (ClassNotFoundException e) {
					    // handle exception
					} catch (InstantiationException e) {
					    // handle exception
					} catch (IllegalAccessException e) {
					    // handle exception
					}
					Main window = new Main();
					window.frmIdeb.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

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

	/**
	 * Initialize the contents of the frame.
	 */
	JTabbedPane tabbedPane;
	JPanel info = new Info();
	
	private void initialize() {
		JPanel info = new Info();
		frmIdeb = new JFrame();
		frmIdeb.setTitle("iDEB");
		frmIdeb.setResizable(false);
		frmIdeb.setBounds(100, 100, 622, 589);
		frmIdeb.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frmIdeb.getContentPane().setLayout(new BorderLayout(0, 0));
		
		tabbedPane = new JTabbedPane(JTabbedPane.TOP);
		
		tabbedPane.addTab("Info", info);
		frmIdeb.getContentPane().add(tabbedPane);
		
		JMenuBar menuBar = new JMenuBar();
		frmIdeb.setJMenuBar(menuBar);
		
		JMenu mnFile = new JMenu("File");
		menuBar.add(mnFile);
		
		JMenuItem mntmNewMenuItem = new JMenuItem("Quit");
		mnFile.add(mntmNewMenuItem);
	}
	
	
}



Info.java


import javax.swing.JPanel;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.border.TitledBorder;
import javax.swing.UIManager;
import java.awt.Color;
import javax.swing.JTextPane;
import javax.swing.JTextArea;
import java.awt.Font;
import javax.swing.JScrollPane;
import javax.swing.JComboBox;
import javax.swing.DefaultComboBoxModel;

public class Info extends JPanel {
	public static JTextField textField;
	private JTextField textField_1;
	private JTextField textField_2;
	private JTextField textField_3;
	private JTextField textField_6;
	private JTextField textField_7;
	private JTextField textField_5;
	private JTextField textField_9;
	/**
	 * Create the panel.
	 */
	public Info() {
		
		JPanel panel = new JPanel();
		panel.setBorder(new TitledBorder(null, "Required", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		
		JPanel panel_1 = new JPanel();
		panel_1.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Recommended", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0)));
		
		JLabel lblSection = new JLabel("Section");
		
		textField_6 = new JTextField();
		textField_6.setColumns(10);
		
		JLabel lblShortDescription = new JLabel("Short Description");
		
		textField_7 = new JTextField();
		textField_7.setColumns(10);
		
		JLabel lblPriority = new JLabel("Priority");
		
		JLabel lblLongDescription = new JLabel("Long Description");
		
		JScrollPane scrollPane = new JScrollPane();
		
		JComboBox comboBox_2 = new JComboBox();
		comboBox_2.setModel(new DefaultComboBoxModel(new String[] {"Extra", "Important", "Optional", "Required", "Standard"}));
		comboBox_2.setSelectedIndex(4);
		GroupLayout gl_panel_1 = new GroupLayout(panel_1);
		gl_panel_1.setHorizontalGroup(
			gl_panel_1.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panel_1.createSequentialGroup()
					.addContainerGap()
					.addGroup(gl_panel_1.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_panel_1.createSequentialGroup()
							.addComponent(lblSection)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(textField_6, GroupLayout.PREFERRED_SIZE, 239, GroupLayout.PREFERRED_SIZE)
							.addPreferredGap(ComponentPlacement.UNRELATED)
							.addComponent(lblPriority)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(comboBox_2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
						.addComponent(lblShortDescription)
						.addComponent(lblLongDescription)
						.addComponent(scrollPane, GroupLayout.DEFAULT_SIZE, 548, Short.MAX_VALUE)
						.addComponent(textField_7, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 548, Short.MAX_VALUE))
					.addContainerGap())
		);
		gl_panel_1.setVerticalGroup(
			gl_panel_1.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panel_1.createSequentialGroup()
					.addGroup(gl_panel_1.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblSection)
						.addComponent(lblPriority)
						.addComponent(textField_6, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(comboBox_2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(lblShortDescription)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(textField_7, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(lblLongDescription)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(scrollPane, GroupLayout.DEFAULT_SIZE, 102, Short.MAX_VALUE)
					.addContainerGap())
		);
		
		JTextPane textPane = new JTextPane();
		scrollPane.setViewportView(textPane);
		panel_1.setLayout(gl_panel_1);
		
		JPanel panel_2 = new JPanel();
		panel_2.setBorder(new TitledBorder(null, "Optional", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		GroupLayout groupLayout = new GroupLayout(this);
		groupLayout.setHorizontalGroup(
			groupLayout.createParallelGroup(Alignment.TRAILING)
				.addGroup(groupLayout.createSequentialGroup()
					.addContainerGap()
					.addGroup(groupLayout.createParallelGroup(Alignment.TRAILING)
						.addComponent(panel_2, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 588, Short.MAX_VALUE)
						.addComponent(panel, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 588, Short.MAX_VALUE)
						.addComponent(panel_1, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 588, Short.MAX_VALUE))
					.addContainerGap())
		);
		groupLayout.setVerticalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addContainerGap()
					.addComponent(panel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(panel_1, GroupLayout.PREFERRED_SIZE, 232, GroupLayout.PREFERRED_SIZE)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(panel_2, GroupLayout.PREFERRED_SIZE, 111, GroupLayout.PREFERRED_SIZE)
					.addContainerGap(15, Short.MAX_VALUE))
		);
		
		JLabel lblSource = new JLabel("Source");
		
		textField_5 = new JTextField();
		textField_5.setColumns(10);
		
		JLabel lblHomepage = new JLabel("Homepage");
		
		textField_9 = new JTextField();
		textField_9.setColumns(10);
		
		JLabel lblEssential = new JLabel("Essential");
		
		JComboBox comboBox = new JComboBox();
		comboBox.setModel(new DefaultComboBoxModel(new String[] {"No", "Yes"}));
		GroupLayout gl_panel_2 = new GroupLayout(panel_2);
		gl_panel_2.setHorizontalGroup(
			gl_panel_2.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panel_2.createSequentialGroup()
					.addContainerGap()
					.addGroup(gl_panel_2.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_panel_2.createSequentialGroup()
							.addComponent(lblSource)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(textField_5, GroupLayout.PREFERRED_SIZE, 228, GroupLayout.PREFERRED_SIZE)
							.addPreferredGap(ComponentPlacement.UNRELATED)
							.addComponent(lblHomepage)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(textField_9, GroupLayout.DEFAULT_SIZE, 218, Short.MAX_VALUE))
						.addGroup(gl_panel_2.createSequentialGroup()
							.addComponent(lblEssential)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(comboBox, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
					.addContainerGap())
		);
		gl_panel_2.setVerticalGroup(
			gl_panel_2.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panel_2.createSequentialGroup()
					.addGroup(gl_panel_2.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblSource)
						.addComponent(textField_5, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(lblHomepage)
						.addComponent(textField_9, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(ComponentPlacement.UNRELATED)
					.addGroup(gl_panel_2.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblEssential)
						.addComponent(comboBox, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addContainerGap(31, Short.MAX_VALUE))
		);
		panel_2.setLayout(gl_panel_2);
		
		JLabel lblP = new JLabel("Package");
		
		textField = new JTextField();
		textField.setColumns(10);
		
		JLabel lblVersion = new JLabel("Version");
		
		textField_1 = new JTextField();
		textField_1.setColumns(10);
		
		JLabel lblNewLabel = new JLabel("Maintainer");
		
		textField_2 = new JTextField();
		textField_2.setColumns(10);
		
		JLabel lblEmail = new JLabel("Email");
		
		textField_3 = new JTextField();
		textField_3.setColumns(10);
		
		JLabel lblArchiteccture = new JLabel("Architecture");
		
		JComboBox comboBox_1 = new JComboBox();
		comboBox_1.setModel(new DefaultComboBoxModel(new String[] {"all", "amd64", "iphoneos-arm", "i366", "powerpc"}));
		comboBox_1.setSelectedIndex(0);
		comboBox_1.setEditable(true);
		GroupLayout gl_panel = new GroupLayout(panel);
		gl_panel.setHorizontalGroup(
			gl_panel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panel.createSequentialGroup()
					.addContainerGap()
					.addGroup(gl_panel.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_panel.createSequentialGroup()
							.addComponent(lblArchiteccture)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(comboBox_1, 0, 215, Short.MAX_VALUE))
						.addGroup(gl_panel.createSequentialGroup()
							.addComponent(lblP)
							.addGap(18)
							.addComponent(textField, GroupLayout.PREFERRED_SIZE, 220, GroupLayout.PREFERRED_SIZE))
						.addGroup(gl_panel.createSequentialGroup()
							.addComponent(lblNewLabel)
							.addPreferredGap(ComponentPlacement.UNRELATED)
							.addComponent(textField_2)))
					.addGap(10)
					.addGroup(gl_panel.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_panel.createSequentialGroup()
							.addComponent(lblVersion)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(textField_1, GroupLayout.DEFAULT_SIZE, 221, Short.MAX_VALUE))
						.addGroup(gl_panel.createSequentialGroup()
							.addComponent(lblEmail)
							.addGap(18)
							.addComponent(textField_3, GroupLayout.DEFAULT_SIZE, 218, Short.MAX_VALUE)))
					.addContainerGap())
		);
		gl_panel.setVerticalGroup(
			gl_panel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panel.createSequentialGroup()
					.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblP)
						.addComponent(lblVersion)
						.addComponent(textField_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(textField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(ComponentPlacement.UNRELATED)
					.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblNewLabel)
						.addComponent(textField_2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(lblEmail)
						.addComponent(textField_3, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(ComponentPlacement.UNRELATED)
					.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblArchiteccture)
						.addComponent(comboBox_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
		);
		panel.setLayout(gl_panel);
		setLayout(groupLayout);

	}
}



It's just a GUI at the moment.

P.S. I think we're all getting a bit confused. This is my code that puts a JPanel inside a TabbedPane, not a JFrame. In Main.java, I need to access the textField variable, but I can't do that when the variable is initialized.
Was This Post Helpful? 0
  • +
  • -

#10 oha055  Icon User is offline

  • D.I.C Regular

Reputation: 49
  • View blog
  • Posts: 271
  • Joined: 02-February 09

Re: Accessing controls in JFrame from parent.

Posted 15 April 2012 - 10:37 AM

Change JPanel info = new Info(); to Info info = new Info();

info.textField.getText(); works now

This post has been edited by oha055: 15 April 2012 - 10:38 AM

Was This Post Helpful? 0
  • +
  • -

#11 KClO3  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 16-March 12

Re: Accessing controls in JFrame from parent.

Posted 15 April 2012 - 10:53 AM

View Postoha055, on 15 April 2012 - 10:37 AM, said:

Change JPanel info = new Info(); to Info info = new Info();

info.textField.getText(); works now

Oh my god....I new it would be a simple mistake. Thanks a bunch everyone!
Was This Post Helpful? 0
  • +
  • -

#12 oha055  Icon User is offline

  • D.I.C Regular

Reputation: 49
  • View blog
  • Posts: 271
  • Joined: 02-February 09

Re: Accessing controls in JFrame from parent.

Posted 15 April 2012 - 10:56 AM

View PostKClO3, on 15 April 2012 - 07:53 PM, said:

View Postoha055, on 15 April 2012 - 10:37 AM, said:

Change JPanel info = new Info(); to Info info = new Info();

info.textField.getText(); works now

Oh my god....I new it would be a simple mistake. Thanks a bunch everyone!



Glad to be of help! :balloon:
Was This Post Helpful? 0
  • +
  • -

#13 KClO3  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 16-March 12

Re: Accessing controls in JFrame from parent.

Posted 15 April 2012 - 11:40 AM

And I also just made myself look like an idiot by saying 'new'. I meant 'knew'. C'mon, autocorrect!
Was This Post Helpful? 0
  • +
  • -

#14 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8342
  • View blog
  • Posts: 31,880
  • Joined: 06-March 08

Re: Accessing controls in JFrame from parent.

Posted 15 April 2012 - 11:56 AM

View Postpbl, on 15 April 2012 - 01:06 PM, said:

View PostKClO3, on 15 April 2012 - 01:00 PM, said:

I'm assuming that you meant you can't put a JFrame into a TabbedPane. I assure you, you can. I have it right here on my screen! :P.

Post that code, I am anxious to see it :)

Info is a JPanel not a JFrame :P

See how it is important to post "good" code snippet.
Was This Post Helpful? 0
  • +
  • -

#15 KClO3  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 16-March 12

Re: Accessing controls in JFrame from parent.

Posted 15 April 2012 - 12:54 PM

View Postpbl, on 15 April 2012 - 11:56 AM, said:

View Postpbl, on 15 April 2012 - 01:06 PM, said:

View PostKClO3, on 15 April 2012 - 01:00 PM, said:

I'm assuming that you meant you can't put a JFrame into a TabbedPane. I assure you, you can. I have it right here on my screen! :P.

Post that code, I am anxious to see it :)

Info is a JPanel not a JFrame :P

See how it is important to post "good" code snippet.

Yeah, but if you look, you could've seen that error in the first post :)
Thanks, all.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2