0

Could someone please tell me why is my JScrollPane not aligning together with my JLabel of description?
I want my label "Description:" to be right next to my JScrollPane which contains a JEditorPane.

import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.SplashScreen;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.FileNotFoundException;
import java.io.PrintStream;

import javax.swing.*;

public class Panel extends JPanel
{
	//Variables Start here
	JMenuBar bar = new JMenuBar();
	JMenu file  = new JMenu("File"),format = new JMenu("Format"),help = new JMenu("Help");
	JMenuItem close = new JMenuItem("Exit"), about = new JMenuItem("About");
	JLabel  rName = new JLabel("Recipe Name:") ,label = new JLabel("Description:");
	JEditorPane des = new JEditorPane();
	JScrollPane desHolder = new JScrollPane(des);
	SplashScreen splash;
	//variables end here

	public Panel()
	{
		GridBagLayout grid = new GridBagLayout();
		GridBagConstraints c = new GridBagConstraints();
		setLayout(grid);
		bar.add(file);bar.add(format);bar.add(help);
		help.add(about); file.add(close);
		close.addActionListener(new closeScreen());
		
		c.fill = GridBagConstraints.HORIZONTAL;
		c.gridx=0;
		c.gridy=0;
		c.weightx = GridBagConstraints.REMAINDER;
		add(bar, c); // added bar to the whole horizontal spaces
		
		
		c.gridy = 1;
		
		c.anchor = GridBagConstraints.WEST;
		c.fill = GridBagConstraints.FIRST_LINE_START;
		add(label,c);
		c.fill = GridBagConstraints.BOTH;
		c.anchor = GridBagConstraints.FIRST_LINE_START;
		c.gridx=1;
		c.weightx = 1.0 ;
		c.weighty = 1.5;
		add(desHolder,c);
		
		c.gridx=0; c.gridy=2; 
		add(rName,c);
	}

	//start methods, actionListener, handlers etc here
	public void printThis(String s)
	{
		System.out.println(s);
	}
	
	private class closeScreen implements ActionListener 
	{
		public void actionPerformed(ActionEvent e)
		{
			System.exit(0);
		}
	}
	
}
2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by autorunman22
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.