Hello forum, Vaironl here.
I already asked this question with no luck. So now I will to repost it without the code.

I have a JPanel which contains labelsand JTextField + other components.
When I minize the window and then restore it The components stay in place but the are re sizing off screen ( The end is getting bigger, for example if a Jtextfield was 40char long now is 80char long).

Any suggestion about what might be doing this? I have the code if needed.
I assume it might be the GridBagConstraints.

Recommended Answers

All 11 Replies

just send that code dude... dono how's this possible ... will clear this issue..

just send that code dude... dono how's this possible ... will clear this issue..

Main class/Frame

import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.io.ObjectInputStream.GetField;

import javax.swing.*;

public class Frame {
	private static final int WIDTH=900;
	private static final int HEIGHT=800;
	private static JFrame frame = new JFrame("Recipe Application");
	private static final Panel panel = new Panel();
	public static void main(String[] args)
	{
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setSize(WIDTH,HEIGHT);
		frame.setLayout(new FlowLayout(FlowLayout.LEFT));
		frame.add(panel);
		frame.setResizable(false);
		frame.setVisible(true);
		frame.setLocationRelativeTo(null);
		
		
	}

}

Panel class

import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.SplashScreen;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Scanner;

import javax.swing.*;
import javax.swing.filechooser.FileNameExtensionFilter;

public class Panel extends JPanel
{
	//Variables Start here
	private JMenuBar bar = new JMenuBar();
	private  JMenu file  = new JMenu("File"),format = new JMenu("Format"),help = new JMenu("Help");
	private  JMenuItem open = new JMenuItem("Open"), close = new JMenuItem("Exit"), about = new JMenuItem("About"), 
			save = new JMenuItem("Save");


	private JTextField recipeField, authorField;
	private JTextField ingredientField[] = new JTextField[40], amountField[] = new JTextField[40],
			unitField[] = new JTextField[40];
	private JComboBox ratingBox = new JComboBox(), servingBox = new JComboBox();

	private JEditorPane descriptionEditor = new JEditorPane();
	private JScrollPane descriptionHolder = new JScrollPane(descriptionEditor);

	private JPanel subPanel = new JPanel();
	private JScrollPane ingredientScroll = new JScrollPane(subPanel);

	private Recipe recipe = new Recipe();

	//variables end

	public Panel()
	{
		setLayout(new GridBagLayout());
		GridBagConstraints c = new GridBagConstraints();
		bar.add(file);bar.add(format);bar.add(help);
		help.add(about); file.add(open); file.add(save); file.add(close); 

		close.addActionListener(new closeAction()); save.addActionListener(new saveAction());
		open.addActionListener(new openAction());

		c.gridx=0; c.gridy=0; c.fill = GridBagConstraints.BOTH; c.anchor = GridBagConstraints.NORTH;
		c.weightx = 1.0; Insets insets = new Insets(0, 0,40,0); c.insets = insets;
		add(bar, c);

		insets = new Insets(0, 40,20,0); c.insets = insets;

		for(int set=0;set<40;set++)
		{
			c.gridy++;// move the next component one grid down

			if(set==0){add( new JLabel("Recipe's Name:"),c);  c.ipady=0; recipeField = new JTextField(20);
			c.gridx=1; add(recipeField,c ); c.gridx=0;}

			else if(set==1){add(new JLabel("Author's Name:"),c); c.gridx=1; authorField = new JTextField(20);
			add(authorField, c); c.gridx=0;}

			else if(set==2){add(new JLabel("Serving Size:"),c); c.gridx =1; for(int items=0;items<60;items++)
				servingBox.addItem(items+1); add(servingBox,c);	c.gridx=0;}

			else if(set==3){add(new JLabel("Rating:"),c); c.gridx=1; for(int item=0;item<5;item++){ratingBox.addItem(item+1);}
			add(ratingBox, c);	c.gridx=0;}

			else if(set==4){add(new JLabel("Description:"),c);
			c.ipady=150; c.ipadx=200;
			c.gridx=1; 
			add(descriptionHolder,c);}


		}

		c.gridy++; c.gridx=1;

		subPanel.setLayout(new GridBagLayout());
		GridBagConstraints c2 = new GridBagConstraints();

		c2.gridx =0; c2.gridy++;
		add(ingredientScroll,c);
		ingredientScroll.setPreferredSize(new Dimension(this.getWidth(), 150));

		for(int set=0;set<40;set++)
		{
			ingredientField[set] = new JTextField(15); amountField[set] = new JTextField(4);
			unitField[set] = new JTextField(4);

			subPanel.add(new JLabel("Ingredient "+(set+1)+":"), c2); c2.gridx++;
			subPanel.add(ingredientField[set],c2); c2.gridx++;

			subPanel.add(new JLabel("Amount:"), c2);c2.gridx++;
			subPanel.add(amountField[set],c2); c2.gridx++;

			subPanel.add(new JLabel("Unit:"), c2);c2.gridx++;
			subPanel.add(unitField[set],c2); c2.gridx++;

			c2.gridx=0;
			c2.gridy++;
		}


	}

	//start methods, actionListener, handlers etc here
	public void printThis(String s)
	{
		System.out.println(s);
	}

	private class closeAction implements ActionListener 
	{
		public void actionPerformed(ActionEvent e)
		{
			System.exit(0);
		}
	}

	private class saveAction implements ActionListener 
	{
		public void actionPerformed(ActionEvent e)
		{
			boolean allowable = true;

			allowable = setRecipeVariables(recipe);


			if(allowable == true)
			{
				JFileChooser sc = new JFileChooser();
				FileNameExtensionFilter filter = new FileNameExtensionFilter(
						"Text Files", "txt");
				sc.setFileFilter(filter);

				int returnValue = sc.showSaveDialog(null);


				if(returnValue == JFileChooser.APPROVE_OPTION)
				{
					try {
						FileWriter writer;
						String blankLine = System.getProperty("line.separator");

						if(String.valueOf(sc.getSelectedFile()).contains(".txt"))
						{
							writer = new FileWriter(sc.getSelectedFile());
						}
						else
						{
							writer = new FileWriter(sc.getSelectedFile()+".txt");
						}

						writer.write(recipe.getRecipeName() + "%" + recipe.getAuthor() + "%" + recipe.getServing()
								+ "%" + recipe.getRating() + "%" + blankLine);

						for(int current=0;current<recipe.getIngredients().length;current++)
						{

							if(current == 0)
							{
								writer.write(recipe.getIngredients()[current]);	
							}
							else if(current == recipe.getIngredients().length-1)
							{
								if(recipe.getIngredients()[current].isEmpty() == false)
								{
									writer.write("," + blankLine + recipe.getIngredients()[current] + "%" );
								}
								else
								{
									writer.write("%" + blankLine);
								}
							}

							else
							{
								if(recipe.getIngredients()[current].isEmpty() == false)
								{
									writer.write("," + blankLine + recipe.getIngredients()[current] );
								}
							}

						}
						
						for(int current=0;current<recipe.getAmounts().length;current++)
						{

							if(current == 0)
							{
								writer.write(recipe.getAmounts()[current].toString());	
							}
							else if(current == recipe.getAmounts().length-1)
							{
								if(recipe.getAmounts()[current].equals(0.0) == false)
								{
									writer.write("," + blankLine + recipe.getAmounts()[current] + "%" );
								}
								else
								{
									writer.write("%" + blankLine);
								}
							}

							else
							{
								if(recipe.getAmounts()[current].equals(0.0) == false)
								{
									writer.write("," + blankLine + recipe.getAmounts()[current]);
								}
							}

						}
						
						for(int current=0;current<recipe.getUnits().length;current++)
						{

							if(current == 0)
							{
								writer.write(recipe.getUnits()[current].toString());	
							}
							else if(current == recipe.getUnits().length-1)
							{
								if(recipe.getUnits()[current].isEmpty() == false)
								{
									writer.write("," + blankLine + recipe.getUnits()[current] + "%" );
								}
								else
								{
									writer.write("%" + blankLine);
								}
							}

							else
							{
								if(recipe.getUnits()[current].isEmpty() == false)
								{
									writer.write("," + blankLine + recipe.getUnits()[current]);
								}
							}

						}
						
						writer.write(recipe.getDescription() + "%");

						writer.close();
					} catch (IOException e1) {
						e1.printStackTrace();
					}
				}
			}

		}
	}

	private class openAction implements ActionListener 
	{
		public void actionPerformed(ActionEvent e)
		{	
			JFileChooser sc = new JFileChooser();
			FileNameExtensionFilter filter = new FileNameExtensionFilter(
					"Text Files", "txt");
			sc.setFileFilter(filter);

			int returnValue = sc.showOpenDialog(null);

			if(returnValue == JFileChooser.APPROVE_OPTION)
			{
				try {
					Scanner scanner = new Scanner(new File(String.valueOf(sc.getSelectedFile())));
				} catch (Exception ex) {
					ex.printStackTrace();
				}
			}
		}
	}

	private boolean setRecipeVariables(Recipe recipe)
	{
		boolean allowed = true;

		if(recipeField.getText().isEmpty()|| authorField.getText().isEmpty() || 
				descriptionEditor.getText().isEmpty() || ingredientField[0].getText().isEmpty() ||
				amountField[0].getText().isEmpty() || unitField[0].getText().isEmpty())
		{
			JOptionPane.showMessageDialog(null, "One or more of the required fields are empty"); 
			allowed = false;
		}
		else
		{
			
			recipe.setRecipeName(recipeField.getText());

			recipe.setAuthorName(authorField.getText());

			recipe.setServing((Integer) servingBox.getSelectedItem());
			
			recipe.setRating(Integer.valueOf(String.valueOf(ratingBox.getSelectedItem())));

			recipe.setRecipeDescription(descriptionEditor.getText());

			for(int set=0;set<recipe.getIngredients().length;set++)
			{
				if(ingredientField[set].getText().isEmpty() == false)
				{
					recipe.setIngredients(ingredientField[set].getText(), set);
				}
				else{
					recipe.setIngredients("", set);
				}
			}

			for(int set=0;set<recipe.getAmounts().length;set++)
			{
				if(amountField[set].getText().isEmpty() == false)
				{
					try{
						recipe.setIngredientAmounts(Double.valueOf(amountField[set].getText()), set);
					}
					catch(NumberFormatException ex)
					{
						JOptionPane.showMessageDialog(null,"The amount fields must be numbers, decimals are\n accepted");
						allowed = false;
						break;
					}
				}
				else{
					recipe.setIngredientAmounts(0.0, set);
				}
			}

			for(int set=0;set<recipe.getUnits().length;set++)
			{

				if(unitField[set].getText().isEmpty() == false)
				{
					recipe.setIngredientUnits(unitField[set].getText(), set);
				}
				else{
					recipe.setIngredientUnits("", set);
				}

			}

		}

		return allowed;
	}

}

Recipe class

public class Recipe {
	private String recipeName,authorName,recipeDescription;
	private String[] ingredientName = new String [40], ingredientUnits = new String [40];
	private Double[] ingredientAmounts = new Double [40];
	private int ratingValue,servingSize;
	
	public Recipe()
	{
		recipeName = "";
		authorName = "";
		ratingValue= 0;
		servingSize= 0;
		recipeDescription = "";
		
		for(int init=0;init<ingredientName.length;init++)
		{
			ingredientName[init] = "";
			ingredientUnits[init] = "";
			ingredientAmounts[init] = 0.0;
		}
	}
	
	public void setRecipeName(String rName)
	{recipeName = rName;}
	
	public void setAuthorName(String aName)
	{authorName = aName;}
	
	public void setIngredients(String ingredients, int location)
	{ingredientName[location] = ingredients;}

	public void setIngredientUnits(String uNames, int location)
	{ingredientUnits[location] = uNames;}
	
	public void setIngredientAmounts(Double aValue, int location)
	{ingredientAmounts[location] = aValue;}
	
	public void setRecipeDescription(String rDescription)
	{recipeDescription = rDescription;}
	
	public void setRating(int rValue)
	{ratingValue = rValue;}
	
	public void setServing(int sSize)
	{servingSize = sSize;}
	
	public String getRecipeName()
	{return recipeName;}
	
	public String getAuthor()
	{return authorName;}
	
	public String[] getIngredients()
	{return ingredientName;}
	
	public String[] getUnits()
	{return ingredientUnits;}
	
	public Double[] getAmounts()
	{return ingredientAmounts;}
	
	public String getDescription()
	{return recipeDescription;}
	
	public int getRating()
	{return ratingValue;}
	
	public int getServing()
	{return servingSize;}
	
}

Main class/Frame

import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.io.ObjectInputStream.GetField;

import javax.swing.*;

public class Frame {
	private static final int WIDTH=900;
	private static final int HEIGHT=800;
	private static JFrame frame = new JFrame("Recipe Application");
	private static final Panel panel = new Panel();
	public static void main(String[] args)
	{
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setSize(WIDTH,HEIGHT);
		frame.setLayout(new FlowLayout(FlowLayout.LEFT));
		frame.add(panel);
		frame.setResizable(false);
		frame.setVisible(true);
		frame.setLocationRelativeTo(null);
		
		
	}

}

Panel class

import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.SplashScreen;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Scanner;

import javax.swing.*;
import javax.swing.filechooser.FileNameExtensionFilter;

public class Panel extends JPanel
{
	//Variables Start here
	private JMenuBar bar = new JMenuBar();
	private  JMenu file  = new JMenu("File"),format = new JMenu("Format"),help = new JMenu("Help");
	private  JMenuItem open = new JMenuItem("Open"), close = new JMenuItem("Exit"), about = new JMenuItem("About"), 
			save = new JMenuItem("Save");


	private JTextField recipeField, authorField;
	private JTextField ingredientField[] = new JTextField[40], amountField[] = new JTextField[40],
			unitField[] = new JTextField[40];
	private JComboBox ratingBox = new JComboBox(), servingBox = new JComboBox();

	private JEditorPane descriptionEditor = new JEditorPane();
	private JScrollPane descriptionHolder = new JScrollPane(descriptionEditor);

	private JPanel subPanel = new JPanel();
	private JScrollPane ingredientScroll = new JScrollPane(subPanel);

	private Recipe recipe = new Recipe();

	//variables end

	public Panel()
	{
		setLayout(new GridBagLayout());
		GridBagConstraints c = new GridBagConstraints();
		bar.add(file);bar.add(format);bar.add(help);
		help.add(about); file.add(open); file.add(save); file.add(close); 

		close.addActionListener(new closeAction()); save.addActionListener(new saveAction());
		open.addActionListener(new openAction());

		c.gridx=0; c.gridy=0; c.fill = GridBagConstraints.BOTH; c.anchor = GridBagConstraints.NORTH;
		c.weightx = 1.0; Insets insets = new Insets(0, 0,40,0); c.insets = insets;
		add(bar, c);

		insets = new Insets(0, 40,20,0); c.insets = insets;

		for(int set=0;set<40;set++)
		{
			c.gridy++;// move the next component one grid down

			if(set==0){add( new JLabel("Recipe's Name:"),c);  c.ipady=0; recipeField = new JTextField(20);
			c.gridx=1; add(recipeField,c ); c.gridx=0;}

			else if(set==1){add(new JLabel("Author's Name:"),c); c.gridx=1; authorField = new JTextField(20);
			add(authorField, c); c.gridx=0;}

			else if(set==2){add(new JLabel("Serving Size:"),c); c.gridx =1; for(int items=0;items<60;items++)
				servingBox.addItem(items+1); add(servingBox,c);	c.gridx=0;}

			else if(set==3){add(new JLabel("Rating:"),c); c.gridx=1; for(int item=0;item<5;item++){ratingBox.addItem(item+1);}
			add(ratingBox, c);	c.gridx=0;}

			else if(set==4){add(new JLabel("Description:"),c);
			c.ipady=150; c.ipadx=200;
			c.gridx=1; 
			add(descriptionHolder,c);}


		}

		c.gridy++; c.gridx=1;

		subPanel.setLayout(new GridBagLayout());
		GridBagConstraints c2 = new GridBagConstraints();

		c2.gridx =0; c2.gridy++;
		add(ingredientScroll,c);
		ingredientScroll.setPreferredSize(new Dimension(this.getWidth(), 150));

		for(int set=0;set<40;set++)
		{
			ingredientField[set] = new JTextField(15); amountField[set] = new JTextField(4);
			unitField[set] = new JTextField(4);

			subPanel.add(new JLabel("Ingredient "+(set+1)+":"), c2); c2.gridx++;
			subPanel.add(ingredientField[set],c2); c2.gridx++;

			subPanel.add(new JLabel("Amount:"), c2);c2.gridx++;
			subPanel.add(amountField[set],c2); c2.gridx++;

			subPanel.add(new JLabel("Unit:"), c2);c2.gridx++;
			subPanel.add(unitField[set],c2); c2.gridx++;

			c2.gridx=0;
			c2.gridy++;
		}


	}

	//start methods, actionListener, handlers etc here
	public void printThis(String s)
	{
		System.out.println(s);
	}

	private class closeAction implements ActionListener 
	{
		public void actionPerformed(ActionEvent e)
		{
			System.exit(0);
		}
	}

	private class saveAction implements ActionListener 
	{
		public void actionPerformed(ActionEvent e)
		{
			boolean allowable = true;

			allowable = setRecipeVariables(recipe);


			if(allowable == true)
			{
				JFileChooser sc = new JFileChooser();
				FileNameExtensionFilter filter = new FileNameExtensionFilter(
						"Text Files", "txt");
				sc.setFileFilter(filter);

				int returnValue = sc.showSaveDialog(null);


				if(returnValue == JFileChooser.APPROVE_OPTION)
				{
					try {
						FileWriter writer;
						String blankLine = System.getProperty("line.separator");

						if(String.valueOf(sc.getSelectedFile()).contains(".txt"))
						{
							writer = new FileWriter(sc.getSelectedFile());
						}
						else
						{
							writer = new FileWriter(sc.getSelectedFile()+".txt");
						}

						writer.write(recipe.getRecipeName() + "%" + recipe.getAuthor() + "%" + recipe.getServing()
								+ "%" + recipe.getRating() + "%" + blankLine);

						for(int current=0;current<recipe.getIngredients().length;current++)
						{

							if(current == 0)
							{
								writer.write(recipe.getIngredients()[current]);	
							}
							else if(current == recipe.getIngredients().length-1)
							{
								if(recipe.getIngredients()[current].isEmpty() == false)
								{
									writer.write("," + blankLine + recipe.getIngredients()[current] + "%" );
								}
								else
								{
									writer.write("%" + blankLine);
								}
							}

							else
							{
								if(recipe.getIngredients()[current].isEmpty() == false)
								{
									writer.write("," + blankLine + recipe.getIngredients()[current] );
								}
							}

						}
						
						for(int current=0;current<recipe.getAmounts().length;current++)
						{

							if(current == 0)
							{
								writer.write(recipe.getAmounts()[current].toString());	
							}
							else if(current == recipe.getAmounts().length-1)
							{
								if(recipe.getAmounts()[current].equals(0.0) == false)
								{
									writer.write("," + blankLine + recipe.getAmounts()[current] + "%" );
								}
								else
								{
									writer.write("%" + blankLine);
								}
							}

							else
							{
								if(recipe.getAmounts()[current].equals(0.0) == false)
								{
									writer.write("," + blankLine + recipe.getAmounts()[current]);
								}
							}

						}
						
						for(int current=0;current<recipe.getUnits().length;current++)
						{

							if(current == 0)
							{
								writer.write(recipe.getUnits()[current].toString());	
							}
							else if(current == recipe.getUnits().length-1)
							{
								if(recipe.getUnits()[current].isEmpty() == false)
								{
									writer.write("," + blankLine + recipe.getUnits()[current] + "%" );
								}
								else
								{
									writer.write("%" + blankLine);
								}
							}

							else
							{
								if(recipe.getUnits()[current].isEmpty() == false)
								{
									writer.write("," + blankLine + recipe.getUnits()[current]);
								}
							}

						}
						
						writer.write(recipe.getDescription() + "%");

						writer.close();
					} catch (IOException e1) {
						e1.printStackTrace();
					}
				}
			}

		}
	}

	private class openAction implements ActionListener 
	{
		public void actionPerformed(ActionEvent e)
		{	
			JFileChooser sc = new JFileChooser();
			FileNameExtensionFilter filter = new FileNameExtensionFilter(
					"Text Files", "txt");
			sc.setFileFilter(filter);

			int returnValue = sc.showOpenDialog(null);

			if(returnValue == JFileChooser.APPROVE_OPTION)
			{
				try {
					Scanner scanner = new Scanner(new File(String.valueOf(sc.getSelectedFile())));
				} catch (Exception ex) {
					ex.printStackTrace();
				}
			}
		}
	}

	private boolean setRecipeVariables(Recipe recipe)
	{
		boolean allowed = true;

		if(recipeField.getText().isEmpty()|| authorField.getText().isEmpty() || 
				descriptionEditor.getText().isEmpty() || ingredientField[0].getText().isEmpty() ||
				amountField[0].getText().isEmpty() || unitField[0].getText().isEmpty())
		{
			JOptionPane.showMessageDialog(null, "One or more of the required fields are empty"); 
			allowed = false;
		}
		else
		{
			
			recipe.setRecipeName(recipeField.getText());

			recipe.setAuthorName(authorField.getText());

			recipe.setServing((Integer) servingBox.getSelectedItem());
			
			recipe.setRating(Integer.valueOf(String.valueOf(ratingBox.getSelectedItem())));

			recipe.setRecipeDescription(descriptionEditor.getText());

			for(int set=0;set<recipe.getIngredients().length;set++)
			{
				if(ingredientField[set].getText().isEmpty() == false)
				{
					recipe.setIngredients(ingredientField[set].getText(), set);
				}
				else{
					recipe.setIngredients("", set);
				}
			}

			for(int set=0;set<recipe.getAmounts().length;set++)
			{
				if(amountField[set].getText().isEmpty() == false)
				{
					try{
						recipe.setIngredientAmounts(Double.valueOf(amountField[set].getText()), set);
					}
					catch(NumberFormatException ex)
					{
						JOptionPane.showMessageDialog(null,"The amount fields must be numbers, decimals are\n accepted");
						allowed = false;
						break;
					}
				}
				else{
					recipe.setIngredientAmounts(0.0, set);
				}
			}

			for(int set=0;set<recipe.getUnits().length;set++)
			{

				if(unitField[set].getText().isEmpty() == false)
				{
					recipe.setIngredientUnits(unitField[set].getText(), set);
				}
				else{
					recipe.setIngredientUnits("", set);
				}

			}

		}

		return allowed;
	}

}

Recipe class

public class Recipe {
	private String recipeName,authorName,recipeDescription;
	private String[] ingredientName = new String [40], ingredientUnits = new String [40];
	private Double[] ingredientAmounts = new Double [40];
	private int ratingValue,servingSize;
	
	public Recipe()
	{
		recipeName = "";
		authorName = "";
		ratingValue= 0;
		servingSize= 0;
		recipeDescription = "";
		
		for(int init=0;init<ingredientName.length;init++)
		{
			ingredientName[init] = "";
			ingredientUnits[init] = "";
			ingredientAmounts[init] = 0.0;
		}
	}
	
	public void setRecipeName(String rName)
	{recipeName = rName;}
	
	public void setAuthorName(String aName)
	{authorName = aName;}
	
	public void setIngredients(String ingredients, int location)
	{ingredientName[location] = ingredients;}

	public void setIngredientUnits(String uNames, int location)
	{ingredientUnits[location] = uNames;}
	
	public void setIngredientAmounts(Double aValue, int location)
	{ingredientAmounts[location] = aValue;}
	
	public void setRecipeDescription(String rDescription)
	{recipeDescription = rDescription;}
	
	public void setRating(int rValue)
	{ratingValue = rValue;}
	
	public void setServing(int sSize)
	{servingSize = sSize;}
	
	public String getRecipeName()
	{return recipeName;}
	
	public String getAuthor()
	{return authorName;}
	
	public String[] getIngredients()
	{return ingredientName;}
	
	public String[] getUnits()
	{return ingredientUnits;}
	
	public Double[] getAmounts()
	{return ingredientAmounts;}
	
	public String getDescription()
	{return recipeDescription;}
	
	public int getRating()
	{return ratingValue;}
	
	public int getServing()
	{return servingSize;}
	
}

maybe you coud try setting the bounds of components by setBounds() and setMaximumSize(Dimension) and even setPreferredSize(Dimension) methods?

maybe you coud try setting the bounds of components by setBounds() and setMaximumSize(Dimension) and even setPreferredSize(Dimension) methods?

Thanks for the suggestion but I believe I found the one line of code that it's making it act this way.

The Frame layout is set to FlowLayout.Left

When I change it, it doesn't move but the position is disoriented.
I tried different layouts but I can't figure out how to fix it.

Thanks for the suggestion but I believe I found the one line of code that it's making it act this way.

The Frame layout is set to FlowLayout.Left

When I change it, it doesn't move but the position is disoriented.
I tried different layouts but I can't figure out how to fix it.

Check here i hope this may help:http://java.sun.com/developer/onlineTraining/GUI/AWTLayoutMgr/shortcourse.html and here is a link on a whole bunch of layouts and how to use them:http://java.sun.com/developer/technicalArticles/GUI/AWTLayoutMgr/

@cOrRuPtG3n3t!x

what's an aswers is

maybe you coud try setting the bounds of components by setBounds() and setMaximumSize(Dimension) and even setPreferredSize(Dimension) methods?

no never setBounds, this is job for LayoutManager, occasionally you can place that by take Insets, but why not use MigLayout

most of LayoutManagers pretty ignored setXxxSize

@vaironl

1) class Frame

- never set Name for class that could be in conflict with API or methods name, rename that as MyFrame
- same for your second class with name Panel, remane that to MyPanel
- every java imports (excluding FlowLayout) are useless
- JFrame (from Java5) have got implemented BOrderLayout by Default
- frame.setVisible(true); would be last line in main method

then will be come rest ....

@cOrRuPtG3n3t!x

what's an aswers is

maybe you coud try setting the bounds of components by setBounds() and setMaximumSize(Dimension) and even setPreferredSize(Dimension) methods?

no never setBounds, this is job for LayoutManager, occasionally you can place that by take Insets, but why not use MigLayout

most of LayoutManagers pretty ignored setXxxSize

I dont really get what you mean, but i was just suggesting methods i thought that would make components usually non resizeable,seems they didnt work. but atleast you gave the OP a better solution then me:)

Only important comment as I feel that, wrong experiences ....

@vaironl

1) class Frame

- never set Name for class that could be in conflict with API or methods name, rename that as MyFrame
- same for your second class with name Panel, remane that to MyPanel
- every java imports (excluding FlowLayout) are useless
- JFrame (from Java5) have got implemented BOrderLayout by Default
- frame.setVisible(true); would be last line in main method

then will be come rest ....

Thanks Mr.Korbel.

I fixed up many things on the panel and the frame which are now different.
I noticed that the insets might also be playing a part in this. Both the FlowLayout, and Insets are causing problems, I will try to fiddle more with them.

Fixed it, the problem was the padding of the ScrollPane.
I changed the size of all padded components to fit the screen

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.