public class LineChart extends JPanel { public void printLegend(){ JLabel legend = new JLabel(); legend.setText("/ FirstLineß\n"+"/ SecondLine"); legend.setBorder(new TitledBorder("Legende")); legend.setSize(legend.getSize()); // legend.set) // legend.setSize(50, 150); this.add(legend); } @Override protected void paintComponent(Graphics g){ this.printLegend(); } } public class Test { public static void main(String[] args) { JFrame f = new JFrame("Try to do it right!"); f.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); f.setSize( 500, 500 ); f.add( new LineChart() ); f.setVisible( true ); f.repaint(); } }