setSize problem!

hi allIs there any reason for setSize doesn抰 work?i dont why, its not working for me! :-(i have a class which extends JFrame and ihv added setSize(600,500) in constructor, juzt after super(title) !someone please help me!thanks and regardssarathy
[294 byte] By [JavaAddicta] at [2007-10-2 17:52:43]
# 1
hi Post u r code: without that can't figure out the problem..also check if you might have called pack() function after setSize(...)
Trushanta at 2007-7-13 19:11:06 > top of Java-index,Desktop,Core GUI APIs...
# 2

Have you created any instance of JFrame inside your class?If you have created it

use

JFrameinstancename.setSize(..)

If you have not created anyinstance of JFrame inside your class.Use

new yourclassname().setSize(..) instead of setSize(..)

Hope this will help you

Gcona at 2007-7-13 19:11:06 > top of Java-index,Desktop,Core GUI APIs...
# 3

hi im so sorry to post this lengthy code.

in the constructor part, im reading a text file to load the list box.

import javax.swing.*;

import javax.swing.event.*;

import java.awt.*;

import java.awt.event.*;

import java.io.*;

import org.jfree.ui.RefineryUtilities;

public class ChartMaster extends JFrame implements ActionListener, ListSelectionListener {

JList pfoList;

String[] selectedPFO;

/**

* Create the GUI and show it. For thread safety, this method should be invoked

* from the event-dispatching thread (main in my case)

*/

public ChartMaster(String title) {

super(title);

setSize(800,600);

//Create GUI look and feel as that of OS look and feel

try {

UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

} catch (Exception e) {e.printStackTrace(); }

//Make sure we have nice window decorations.

setDefaultLookAndFeelDecorated(true);

//Create and set up the window.

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

Container c = getContentPane();

c.setLayout(new BorderLayout());

//List box

DefaultListModel listModel = loadDefaultListModel("PFOList.txt");

pfoList = new JList(listModel);

pfoList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION );

pfoList.setSelectedIndex(0);

pfoList.addListSelectionListener(this);

pfoList.setVisibleRowCount(5);

JScrollPane listScroller = new JScrollPane(pfoList);

listScroller.setPreferredSize(new Dimension(150, 400));

listScroller.setAlignmentX(LEFT_ALIGNMENT);

JPanel listPane = new JPanel();

listPane.setLayout(new BoxLayout(listPane, BoxLayout.PAGE_AXIS));

JLabel label = new JLabel("Select the PFO(s):");

label.setLabelFor(pfoList);

listPane.add(label);

listPane.add(Box.createRigidArea(new Dimension(0,5)));

listPane.add(listScroller);

listPane.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));

//Date selection

JPanel rightPanel = new JPanel();

rightPanel.setLayout(new BoxLayout(rightPanel, BoxLayout.PAGE_AXIS));

JLabel jl = new JLabel("Date selection");

rightPanel.add(Box.createRigidArea(new Dimension(0,5)));

JRadioButton forMonthYear = new JRadioButton("For the Month and Year");

JRadioButton duringMonthYear = new JRadioButton("During the Month and Year");

ButtonGroup bg = new ButtonGroup();

bg.add(forMonthYear);

bg.add(duringMonthYear);

rightPanel.add(jl);

rightPanel.add(forMonthYear);

rightPanel.add(duringMonthYear);

//rightPanel.add(

//Bottom buttons

JButton button = new JButton("Show me Chart");

button.addActionListener(this);

c.add(listPane, BorderLayout.WEST);

c.add(rightPanel,BorderLayout.CENTER);

c.add(button,BorderLayout.SOUTH);

//Display the window.

pack();

//RefineryUtilities.centerFrameOnScreen(this);

setVisible(true);

}

public void valueChanged(ListSelectionEvent lse){

//System.out.println("List event: " + lse);

Object[] selectedObj = pfoList.getSelectedValues();

selectedPFO = new String[selectedObj.length];

for( int i=0; i < selectedObj.length; i++){

selectedPFO[i] = (String)selectedObj[i];

}

}

public void actionPerformed(ActionEvent e) {

/*

Code to determine what are all the excel sheets to be read goes here

it depends on choices made in the User Interface and File organization!

ADD SOME MORE COMMENTS LATER

*/

PFOBeta.main(new String[]{"Nothing"});

/*for( int i=0; i < selectedPFO.length; i++){

System.out.println(selectedPFO[i]);

}*/

}

public static DefaultListModel loadDefaultListModel(String cfgFileName){

DefaultListModel listModel = new DefaultListModel();

try{

BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(cfgFileName)));

String pfo = br.readLine();

while(pfo != null){

listModel.addElement(pfo);

pfo = br.readLine();

}

br.close();

}catch(Exception e){ System.out.println(e);}

return listModel;

}

public static void main(String[] args) {

ChartMaster cm = new ChartMaster("Process Group Tool");

}

}

JavaAddicta at 2007-7-13 19:11:06 > top of Java-index,Desktop,Core GUI APIs...
# 4
hi Gcon u r real genius :-)i hv changed my code to instancename.setSize()..its working now.Thank you so much for ur help @ right time!Thanks to Trushant also.
JavaAddicta at 2007-7-13 19:11:06 > top of Java-index,Desktop,Core GUI APIs...
# 5
hiNow i got the point,i have to first add all my components and finally set the size.what i did previously is , i set the size before adding the components.thanks all, for ur time and effort.
JavaAddicta at 2007-7-13 19:11:06 > top of Java-index,Desktop,Core GUI APIs...