1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| /*
package panels;
import java.awt.Font;
import java.awt.Graphics;
/**
*
* @author Lethal
*/
public class PanelLabelFit extends javax.swing.JPanel
{
private int lastHeight;
private int currentHeight;
private JLabel jLabel1
/** Creates new form PanelLabelFit */
public PanelLabelFit(String txt)
{
initComponents();
setText(txt);
lastHeight = 10000;
}
public void paint(Graphics g)
{
super.paint(g);
currentHeight = this.getHeight();
if(currentHeight != lastHeight)
{
lastHeight = currentHeight;
Font font = jLabel1.getFont();
int size = this.getHeight()/2;
if(size > 12) size = 12;
jLabel1.setFont(new Font(font.getName(),font.getStyle(),size));
}
}
public void setText(String str)
{
if ( str.length() > 15) jLabel1.setText(str.substring(0,15) + " ");
else jLabel1.setText(str+ " ");
this.setToolTipText(str);
}
private void initComponents()
{
jLabel1 = new javax.swing.JLabel();
setLayout(new java.awt.GridLayout());
jLabel1.setText("jLabel1");
add(jLabel1);
}
} |
Partager