./druid/src/org/dlib/gui/TitledPanel.java

//==============================================================================
//===
//===   TitledPanel
//===
//===   Copyright (C) by Andrea Carboni.
//===   This file may be distributed under the terms of the LGPL license.
//==============================================================================

package org.dlib.gui;

import java.awt.Color;
import java.awt.Component;
import javax.swing.BorderFactory;
import javax.swing.JPanel;
import javax.swing.border.Border;
import javax.swing.border.TitledBorder;
import org.dlib.gui.plaf.WoodyLookAndFeel;

//==============================================================================

public class TitledPanel extends JPanel
{
	private TitledBorder t;

	//---------------------------------------------------------------------------
	//---
	//--- Constructor
	//---
	//---------------------------------------------------------------------------

	public TitledPanel(String title)
	{
		this(title, null);
	}

	//---------------------------------------------------------------------------

	public TitledPanel(String title, Component c)
	{
		Border b = BorderFactory.createEtchedBorder();

		t = BorderFactory.createTitledBorder(b, title);
		t.setTitleJustification(TitledBorder.LEFT);
		t.setTitlePosition(TitledBorder.TOP);
		t.setTitleColor(Color.black);

		setBorder(t);
		setFont(WoodyLookAndFeel.titleFont);

		if (c != null)
		{
			FlexLayout fl = new FlexLayout(1,1);
			fl.setColProp(0, FlexLayout.EXPAND);
			fl.setRowProp(0, FlexLayout.EXPAND);
			setLayout(fl);

			add("0,0,x,x", c);
		}
	}

	//---------------------------------------------------------------------------
	//---
	//--- API methods
	//---
	//---------------------------------------------------------------------------

	public void setTitle(String title)
	{
		t.setTitle(title);
		repaint();
	}
}

//==============================================================================