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
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");
}
}