Search code examples
javaswingjcomponent

How to make a private swing component a public one in Java?


I want to change the accessibility level of a swing component(i.e jTextArea) so that i can access it in another class! I am using netBeans but it seems it has not visual feature meant for that! This is what i have tried but i got an error which i cannot fix

public class HttpHeadersFrame extends javax.swing.JFrame 
{

/** Creates new form HttpHeadersFrame */

    public HttpHeadersFrame() 
    {
        initComponents();
    }
    public JTextArea getRequestTextArea
    {
       return requestTextArea;//Got error that says "initilizer must be to complete normally"

    }

// Variables declaration - do not modify

private javax.swing.JTextArea requestTextArea;
private javax.swing.JTextArea responseTextArea;

Solution

  • It should be

    //                                 VV
    public JTextArea getRequestTextArea()
    {
       return requestTextArea;//Got error that says "initilizer must be to complete normally"
    
    }
    

    Otherwise, this block is treated as an initializer, and you get a syntax error inside.