| Author |
Dynamically displaying the contents
|
Derek Rodricks
Greenhorn
Joined: Jun 21, 2011
Posts: 2
|
|
I have the following frame that is dynamically loaded when the program is run. But none of the components get loaded when I run the program.
FrontEnd.java
-------------
ublic class FrontEnd extends JFrame implements PropertyChangeListener{
/ * Create the frame
*/
public FrontEnd(String title, ArrayList<Parameter> readwriteList, ArrayList<Parameter> disPlayList)
{
super(title);
_displayList = disPlayList;
_readwriteList = readwriteList;
//Specify an action for the close button
setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
contentPane.setLayout(new BorderLayout(0, 0));
setContentPane(contentPane);
//Set the location of the frame
setLocationRelativeTo(null);
setBounds(100, 100, 953, 496);
// Build the menu bar
buildMenuBar();
contentPane.add(display());
pack();
setVisible(true);
}
private JPanel display()
{
//based on the displayList.size - set the widgets and their values.
Parameter pli;
num_parameters = _displayList.size();
parameterArea = new JPanel(new GridLayout(num_parameters, 1));
ListIterator<Parameter> listDisplay = _displayList.listIterator();
Object obj = null;
JPanel dP = new JPanel(new FlowLayout(FlowLayout.LEFT));
while (listDisplay.hasNext())
{
obj = listDisplay.next();
if (obj instanceof DParm)
{
((DParm) obj).displayParm(dP);
}
dP.setVisible(true);
parameterArea.add(dP);
parameterArea.setVisible(true);
}
pack();
return parameterArea;
}
DParm.java
---------------
@Override
public void displayParm(JPanel widget) {
// TODO Auto-generated method stub
widget = new JPanel(new FlowLayout(FlowLayout.LEFT));
JLabel newLabel = new JLabel();
DecimalFormat df = new DecimalFormat("0.00");
JFormattedTextField newTextArea = new JFormattedTextField(df);
newTextArea.addPropertyChangeListener("value", this);
newTextArea.setColumns(10);
widget.add(newLabel, "left");
widget.add(newTextArea, "right");
widget.setVisible(true);
}
I am unable to figure out why the components are NOT being displayed.
Would appreciate any input.
Thanks.
|
 |
Rob Camick
Ranch Hand
Joined: Jun 13, 2009
Posts: 1788
|
|
When you post code don't forget to use the "Code" tags to the posted code is formatted and readable.
I see where you create "parameterArea" but I don't see where you add the component to the GUI.
If you need more help then post your SSCCE that demonstrates the problem.
|
 |
Derek Rodricks
Greenhorn
Joined: Jun 21, 2011
Posts: 2
|
|
Thanks alot for pointing it out the problem. I was able to display the components.
Thanks again.
|
 |
 |
|
|
subject: Dynamically displaying the contents
|
|
|