hi
i need to design an internal frame tht has the standard menu items.
i have certain fixed field tht need to be visible at all times like the name and age and todays date .... and then i need to have a form where user can input free text. (there are many JTextPanes here). My form exceeds the dimensions of the screen so i need to have a scroll and each text pane has its own scroll too.
i have divided my design as two panels .. the top panel which is always present and the main form ... which is scrollable and can accept user input ...
when i run the code all i see is the top panel and a small dot for the lower panel ... where could i be going wrong
thanks a lot for ur help
here is my code
Code:
import java.awt.*;
import javax.swing.*;
/**
* @author
*/
public class NewReport extends JInternalFrame{
private JPanel reportPanel = new JPanel();
private JMenuBar menuBar = new JMenuBar();
private JMenu fileMenu = new JMenu();
private Rectangle internalBounds;
public NewReport(Rectangle r) {
super.setTitle("Report");
super.setSize(r.width, r.height);
super.setClosable(true);
super.setIconifiable(true);
super.setMaximizable(true);
super.setVisible(true);
internalBounds = new Rectangle(super.getBounds());
getContentPane().add(reportPanel);
reportPanel.setLayout(null);
buildMenu();
super.setJMenuBar(menuBar);
JPanel temp = staticTop();
temp.setPreferredSize(new Dimension((int)(internalBounds.width*.8),42));
temp.setMaximumSize(new Dimension((int)(internalBounds.width*.8),42));
temp.setMinimumSize(new Dimension((int)(internalBounds.width*.8),42));
temp.setBounds((int)(internalBounds.width*.1),05,
temp.getPreferredSize().width, temp.getPreferredSize).height);
reportPanel.add(temp);
temp = mainForm();
temp.setBounds(10,60,internalBounds.width-20,internalBounds.height-80);
System.out.println(temp.getMinimumSize());
System.out.println(temp.getPreferredSize());
System.out.println(temp.getSize());
reportPanel.add(temp);
}
private void buildMenu() {
//fileMenu.setName("File");
fileMenu.setText("File");
menuBar.add(fileMenu);
}
private JPanel staticTop () {
JPanel topPanel = new JPanel();
topPanel.setLayout(new GridLayout(1, 5));
LabelTextFieldCombo firstName = new LabelTextFieldCombo("First Name: ","");
LabelTextFieldCombo middleName = new LabelTextFieldCombo("Middle Name: ","");
LabelTextFieldCombo lastName = new LabelTextFieldCombo("Last Name: ","");
LabelTextFieldCombo age = new LabelTextFieldCombo("Age: ","");
LabelTextFieldCombo date = new LabelTextFieldCombo("Date: ","");
topPanel.add(firstName.getPanel());
topPanel.add(middleName.getPanel());
topPanel.add(lastName.getPanel());
topPanel.add(age.getPanel());
topPanel.add(date.getPanel());
return topPanel;
}
private JPanel mainForm() {
JPanel mainPanel = new JPanel();
JPanel temp = new JPanel();
JScrollPane mainScroll;
temp.setLayout(null);
JTextPane per = new JTextPane();
per.setMinimumSize(new Dimension(internalBounds.width-10,21*6));
per.setPreferredSize(new Dimension(internalBounds.width-10,21*6));
per.setBounds(0,0,per.getPreferredSize().width,per.getPreferredSize().height);
JScrollPane scroll = new JScrollPane(per);
temp.add(scroll);
JTextPane per1 = new JTextPane();
per.setMinimumSize(new Dimension(internalBounds.width-10,21*6));
per1.setPreferredSize(new Dimension(internalBounds.width-10,21*6));
per1.setBounds(0,150,per1.getPreferredSize().width,per1.getPreferredSize().height);
JScrollPane scroll1 = new JScrollPane(per1);
temp.add(scroll1);
mainScroll = new JScrollPane(temp);
mainPanel.add(mainScroll);
return mainPanel;
}
}
Code:
import java.awt.*;
import javax.swing.*;
public class LabelTextFieldCombo {
private JLabel label = new JLabel();
private JTextField textField = new JTextField();
private JPanel panel = new JPanel();
/**
* Default Constructor. initializes the text of JLabel and JTextField
* to "text". The LayoutManager of the JPanel is set to "null"
*/
public LabelTextFieldCombo() {
label.setText("Text");
label.setHorizontalAlignment(SwingConstants.CENTER);
textField.setText("Text");
panel.setLayout(new GridLayout(2, 1));
panel.add(label);
panel.add(textField);
}
/**
*
* @param labelText The text of the JLabel.
* @param textFieldText The text of JTextField
*/
public LabelTextFieldCombo(String labelText, String textFieldText) {
label.setText(labelText);
label.setHorizontalAlignment(SwingConstants.CENTER);
textField.setText(textFieldText);
panel.setLayout(new GridLayout(2,1));
panel.add(label);
panel.add(textField);
}
/**
* @param labelText The text of the JLabel.
* @param textFieldText The text of JTextField.
* @param lm The LayoutManager for the panel.
*/
public LabelTextFieldCombo(String labelText, String textFieldText, LayoutManager lm) {
label.setText(labelText);
label.setHorizontalAlignment(SwingConstants.CENTER);
textField.setText(textFieldText);
panel.setLayout(lm);
panel.add(label);
panel.add(textField);
}
/**
* @param labelText The text of the JLabel.
*/
public void setLabelText(String labelText) {
label.setText(labelText);
}
/**
* @param textFieldText The text of JTextField.
*/
public void setTextFieldText(String textFieldText) {
textField.setText(textFieldText);
}
/**
* @return The text of JLabel.
*/
public String getLabelText() {
return(label.getText());
}
/**
* @return The text of JTextField.
*/
public String getTextFieldText() {
return(textField.getText());
}
/**
* @return The JPanel whose components are JLabel and JTextField.
*/
public JPanel getPanel() {
return(panel);
}
}