arcgissamples\scenario\toc\LabelPanel.java
/* Copyright 2010 ESRI * * All rights reserved under the copyright laws of the United States * and applicable international laws, treaties, and conventions. * * You may freely redistribute and use this sample code, with or * without modification, provided you include the original copyright * notice and use restrictions. * * See the use restrictions. * */ /* * ArcGIS Engine Developer Sample * Application Name: LabelPanel.java */ package arcgissamples.scenario.toc; /**Label panel used to diplay name of the map frame in the TocControl. * Icon and Map title are set using setIcon and setText methods. * doLayout method is used to return the preffered width and heigh of the label. */ import java.awt.Dimension; import javax.swing.Icon; import javax.swing.JLabel; import javax.swing.JPanel; public class LabelPanel extends JPanel { private static final long serialVersionUID = 1L; JLabel label = new JLabel(); public LabelPanel() { //Add a label. add(label); //Sets background color to that of tree control setBackground(javax.swing.UIManager.getColor("Tree.textBackground")); } /**Sets the icon for this label. * @param icon */ public void setIcon(Icon icon) { label.setIcon(icon); } /**Sets the preffered size for the panel. * @see javax.swing.JComponent#getPreferredSize() * @return java.awt.Dimension */ public Dimension getPreferredSize() { return new Dimension(label.getPreferredSize().width, label.getPreferredSize().height); } /**Sets the text for the label * @param stringValue */ public void setText(String stringValue) { label.setText(stringValue); } /** Lays out label based on the prefferred width and height * @see javax.swing.JComponent#doLayout() */ public void doLayout() { label.setLocation(0, 0); label.setBounds(0, 0, label.getPreferredSize().width, label.getPreferredSize().height); } }