/** * show the images as stream of JFrame on desktop */ public void show() { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); JLabel label = null; while (true) { for (int i = 0; i < this.frames.size(); i++) { Frame frame = this.frames.get(i); if (label == null) { label = new JLabel(new ImageIcon(frame.image)); f.getContentPane().add(label); f.pack(); } else { label.getGraphics().drawImage(frame.image,0,0, label); } try {Thread.sleep(frame.delayMillis);} catch (InterruptedException e) {} } } } }
/** Overridden to produce a graphics object even when isDisplayable() is * false, so that calls to getPreferredSize() will return accurate * dimensions (presuming the font and text are set correctly) even when * not onscreen. */ public @Override Graphics getGraphics() { Graphics result = null; if (isDisplayable()) { result = super.getGraphics(); } if (result == null) { result = scratchGraphics(); } return result; }
private JLabel label; public MyComponent() { label = new JLabel("Before Red"); label.setText("<html><u>test</u></html>"); this.add(label); } public void repaint(Graphics g){ g = label.getGraphics(); }
private boolean isCut (String text, int realWidth) { double width = HtmlRenderer.renderHTML(text, resultLabel.getGraphics(), 0, 10, Integer.MAX_VALUE, 20, resultLabel.getFont(), Color.BLACK, HtmlRenderer.STYLE_CLIP, false); return ((int)width) > (realWidth-4); }
JLabel label = new JLabel("xx"); int minWidth = ((int) (label.getFontMetrics(label.getFont()).getStringBounds(label.getText(),label.getGraphics()).getWidth()) + label.getInsets().left + label.getInsets().right);
/** Overridden to produce a graphics object even when isDisplayable() is * false, so that calls to getPreferredSize() will return accurate * dimensions (presuming the font and text are set correctly) even when * not onscreen. */ public Graphics getGraphics() { Graphics result = null; if (isDisplayable()) { result = super.getGraphics(); } if (result == null) { result = scratchGraphics(); } return result; }
/** Overridden to produce a graphics object even when isDisplayable() is * false, so that calls to getPreferredSize() will return accurate * dimensions (presuming the font and text are set correctly) even when * not onscreen. */ public Graphics getGraphics() { Graphics result = null; if (isDisplayable()) { result = super.getGraphics(); } if (result == null) { result = scratchGraphics(); } return result; }
@Override public void itemStateChanged(ItemEvent ie) { try { final int state1 = choice1.getSelectedIndex(); final int state2; if ( state1 == 4 ) state2 = 0; else state2 = choice2.getSelectedIndex(); display.setImage( images[ state1 ][ state2 ].getImage() ); label.update( label.getGraphics() ); } catch( Exception e ){} } });
@Override public void itemStateChanged(ItemEvent ie) { try { final int state1 = choice1.getSelectedIndex(); final int state2; if ( state1 == 4 ) state2 = 0; else state2 = choice2.getSelectedIndex(); // update the texts in choice2 choice2.removeAll(); for ( int i = 0; i < choose2[ state1 ].length; ++i ) choice2.add( choose2[ state1 ][ i ] ); choice2.select( state2 ); display.setImage( images[ state1 ][ state2 ].getImage() ); label.update( label.getGraphics() ); } catch( Exception e ){} } });
int selected = ( (Choice) gd.getChoices().get( 0 )).getSelectedIndex(); label.update( label.getGraphics() ); });