LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 08-13-2004, 11:21 AM   #1
linux_ub
Member
 
Registered: May 2004
Location: NY
Distribution: fedora core 1
Posts: 65

Rep: Reputation: 17
[JAVA] JPanel over JPanel ... not being displayed properly


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


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Resizing a JFrame when JPanel resizes? 95se Programming 1 03-23-2005 04:48 PM
System won't boot properly knoppix doesn't initialize properly rodewan Linux - Software 0 01-23-2005 03:35 PM
java scripts don't load properly MauricioTulua Linux - Software 1 09-17-2004 02:51 PM
(java) mouselistener in JPanel dave bean Programming 6 01-27-2004 12:44 PM
No parameters displayed using ps for java processes beegster Red Hat 0 11-23-2003 05:04 PM


All times are GMT -5. The time now is 09:06 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration