Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
ZuluGod

JAVA Swing textField creating function

Recommended Posts

Posted · Original PosterOP

So I have an assignment requiring the use of lots of textboxes using the java Swing library. Unfortunatly the code to create textfeilds is quite long winded. I would like to be able to call a function

textField(name, grid1);

which then goes and runs a function

public void textField(JTextField text, JPanel gridName){
        text = new JTextField(32);
        gridName.add(text);
}

however the function doesnt like the line textField(name, grid1); giving the error 'name has private access in component'.

Does anyone have any suggestions on how to fix this?

Link to post
Share on other sites

Is name local? Or is it declared in private in another class?

If so, you need to add a getter in that other class


Gaming rig : i5 6600k | EVGA 1070 FTW | 16Go DDR4 HyperX Fury | Intel 600p - WD Black

Laptop : Macbook 2017

Home server : AMD A10 7700k | 2*2TB unraid array + 250GB ssd cache

Link to post
Share on other sites
Posted · Original PosterOP

Name is meant to be a string, but it wont convert string to JTextField

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


×