sandy_2008
Level 7

variable in JLabel in custom code

My requirement is to display a panel which will have some radio buttons and text. the custom code looks like this:


JLabel line1, line2, line3, line4;
JRadioButton Button1, Button2;
static String Button2_Name = "No";
static String Button1_Name = "Yes";
static String VS_Version;
public boolean setupUI(CustomCodePanelProxy customCodePanelProxy)
{
if (initPanel == true)
return true;
initPanel = true;

// capture PanelProxy for later use.
ccpp = customCodePanelProxy;
init();
return true; // display this panel
}
public void init()
{
setLayout(new GridBagLayout());
VS_Version = System.getenv("VS_VERSION");
}
private JPanel createPane()
{
JPanel main = new JPanel(new GridBagLayout());

// set the background as white
main.setBackground(Color.white);
main.setForeground(Color.black);

Insets firstLabelInsets = new Insets(3, 5, 0, 0);
Insets nextLabelInsets = new Insets(5, 5, 0, 0);

GridBagConstraints gbc = new GridBagConstraints();
line1 = new JLabel("These applications require runtime libraries");
line1.setFont(new Font("Dialog", Font.PLAIN, 12));

line2 = new JLabel();
line2.setText("of Visual C++ " + VS_Version + "or higher to run. If you do not have it");
line2.setFont(new Font("Dialog", Font.PLAIN, 12));
......


When the panel is displayed, instead of the value of String "VS_Version", 'null is displayed.
like "These applications require runtime libraries of Visual C++null or higher to run"

Am I doing anything wrong?
Labels (1)
0 Kudos
3 Replies
MEinstaller
Level 7

You need to add the lines to the GridBag layout. Something like add(line1, gbc) after you set the constraints for line1. You will need to do that for each item you are adding to the Panel. Maybe you are already doing that but it doesn't look like it from the code you posted.
0 Kudos
sandy_2008
Level 7

Yes, It's already there in my code.. I posted incomplete code..
The code was working fine.. The only change I did is that I have added the variable in JLabel. But that doesn't seem to work.

Earlier part of code:

line1 = new JLabel("These applications require runtime libraries");
line1.setFont(new Font("Dialog", Font.PLAIN, 12));

line2 = new JLabel("of Visual C++ 2005 or higher to run. If you do not have it");
line2.setFont(new Font("Dialog", Font.PLAIN, 12));


The modified code:

static String VS_Version;
VS_Version = System.getenv("VS_VERSION");

line1 = new JLabel("These applications require runtime libraries");
line1.setFont(new Font("Dialog", Font.PLAIN, 12));

line2 = new JLabel();
line2.setText("of Visual C++ " + VS_Version + "or higher to run. If you do not have it");
line2.setFont(new Font("Dialog", Font.PLAIN, 12));
0 Kudos
MEinstaller
Level 7

I would say that the value that VS_VERSION is getting back must be null then. You can try poping up a dialog box with the value of VS_Version to see what it is, I do this when in development to see what my values are while I am working with them.
0 Kudos