本文整理了Java中javax.swing.JLabel.revalidate()
方法的一些代码示例,展示了JLabel.revalidate()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JLabel.revalidate()
方法的具体详情如下:
包路径:javax.swing.JLabel
类名称:JLabel
方法名:revalidate
暂无
代码示例来源:origin: stackoverflow.com
// Create icon
Icon icon = new ImageIcon(getClass().getResource("/foo/bar/baz.png"));
// Create label
final JLabel lbl = new JLabel("Hello, World", icon, JLabel.LEFT_ALIGNMENT);
// Create button
JButton btn = new JButton("Click Me");
btn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
// Remove icon when button is clicked.
lbl.setIcon(null);
// **IMPORTANT** to call revalidate() to cause JLabel to resize and be repainted.
lbl.revalidate();
}
});
代码示例来源:origin: apache/pdfbox
private void addImage(Image img)
{
// for JDK9; see explanation in PagePane
AffineTransform tx = GraphicsEnvironment.getLocalGraphicsEnvironment().
getDefaultScreenDevice().getDefaultConfiguration().getDefaultTransform();
label.setSize((int) Math.ceil(img.getWidth(null) / tx.getScaleX()),
(int) Math.ceil(img.getHeight(null) / tx.getScaleY()));
label.setIcon(new HighResolutionImageIcon(img, label.getWidth(), label.getHeight()));
label.revalidate();
}
代码示例来源:origin: dboissier/mongo4idea
public JComponent initUi() {
myValueLabel = new JLabel() {
@Override
public String getText() {
return getCurrentText();
}
};
setDefaultForeground();
setFocusable(true);
setBorder(createUnfocusedBorder());
setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
add(myValueLabel);
add(Box.createHorizontalStrut(GAP_BEFORE_ARROW));
add(new JLabel(AllIcons.Ide.Statusbar_arrows));
installChangeListener(() -> {
myValueLabel.revalidate();
myValueLabel.repaint();
});
showPopupMenuOnClick();
showPopupMenuFromKeyboard();
indicateHovering();
indicateFocusing();
return this;
}
代码示例来源:origin: edu.toronto.cs.savant/savant-core
public void updateStatus(String msg) {
this.label_status.setText(msg);
this.label_status.revalidate();
}
代码示例来源:origin: stackoverflow.com
JLabel lbl_test;
lbl_test.setPreferredSize(new Dimension(100, 100) );
lbl_test.revalidate();
代码示例来源:origin: stackoverflow.com
JLabel label = new JLabel();
gui.add(label);
while (a == 1){
String timeStamp = new SimpleDateFormat("hh:mm:ss a").format(Calendar.getInstance().getTime());
label.setText(String.valueOf(timeStamp));
timeStamp = "";
label.revalidate();
}
代码示例来源:origin: org.fudaa.framework.ctulu/ctulu-bu
public void revalidate()
{
if((delegate_==this)||(delegate_==null))
super.revalidate();
else
delegate_.revalidate();
}
代码示例来源:origin: org.gosu-lang.gosu/gosu-lab
public void setStatus( String status )
{
_status.setText( status );
_status.revalidate();
_status.repaint();
}
代码示例来源:origin: stackoverflow.com
public void mouseDragged(MouseEvent e){
JLabel l = (JLabel)e.getSource();
switch(action){
case ResizeWest:
Point p = e.getPoint();
int xDelta = p.x - clickPoint.x;
int width = getWidth() - xDelta;
int x = getX() + xDelta;
l.setSize(width, getHeight()); // call setSize on JLabel l
l.setLocation(x, getY());
l.revalidate();
break;
}
代码示例来源:origin: com.jidesoft/jide-oss
public void propertyChange(PropertyChangeEvent e) {
super.propertyChange(e);
if (JideLabel.PROPERTY_ORIENTATION == e.getPropertyName()) {
if (e.getSource() instanceof JLabel) {
JLabel label = (JLabel) e.getSource();
label.revalidate();
}
}
else if (JideLabel.PROPERTY_CLOCKWISE.equals(e.getPropertyName())) {
if (e.getSource() instanceof JLabel) {
JLabel label = (JLabel) e.getSource();
label.repaint();
}
}
}
}
代码示例来源:origin: igniterealtime/Spark
public void setTitleFont(Font font) {
titleLabel.setFont(font);
titleLabel.validate();
titleLabel.repaint();
titleLabel.revalidate();
}
代码示例来源:origin: freeplane/freeplane
@Override
public void addStatusInfo(final String key, final String info, Icon icon, final String tooltip) {
JLabel label = (JLabel) statusInfos.get(key);
if (label == null) {
label = new JLabel(info);
label.setBorder(BorderFactory.createEtchedBorder());
statusInfos.put(key, label);
statusPanel.add(label, statusPanel.getComponentCount() - 1);
}
else {
label.setText(info);
label.revalidate();
label.repaint();
}
label.setIcon(icon);
label.setToolTipText(tooltip);
label.setVisible(info != null && !info.isEmpty() || icon != null);
}
代码示例来源:origin: igniterealtime/Spark
@Override
public void stateChanged(ChangeEvent e) {
_preview.setBackground(new Color(_sliderarray[0].getValue(), _sliderarray[1].getValue(), _sliderarray[2]
.getValue(), _sliderarray[3].getValue()));
_preview.setForeground(new Color(_sliderarray[0].getValue(), _sliderarray[1].getValue(), _sliderarray[2]
.getValue(), _sliderarray[3].getValue()));
_preview.invalidate();
_preview.repaint();
_preview.revalidate();
Container c = _preview.getParent();
if (c instanceof JPanel) {
c.repaint();
c.revalidate();
}
}
代码示例来源:origin: stackoverflow.com
...
ImageIcon icon = new ImageIcon(img); // your map background as icon
JLabel label = new JLabel(icon); // your map background label
label.setLayout(null);
JLabel dot = new JLabel(new ImageIcon(redDot)); // you need to put some content in your dot label - like
frame.add(label);
Graphics2D g = (Graphics2D) img.getGraphics();
label.add(dot);
// dot.setLocation(1000, 300); // when you use setBounds, you don't need location
dot.setBounds(50, 50, 60, 60); // x-location, y-location, with, height
dot.revalidate(); // just to make sure that your dot actually takes the new bounds and paints it
代码示例来源:origin: stackoverflow.com
label.setIcon(new ImageIcon(image));
frame.setSize(dimension);
label.revalidate();
} catch (Exception ex) {
ex.printStackTrace();
代码示例来源:origin: igniterealtime/Spark
public void setTitleBold(boolean bold) {
Font oldFont = titleLabel.getFont();
Font newFont;
if (bold) {
newFont = new Font(oldFont.getFontName(), Font.BOLD,
oldFont.getSize());
} else {
newFont = new Font(oldFont.getFontName(), Font.PLAIN,
oldFont.getSize());
}
titleLabel.setFont(newFont);
titleLabel.validate();
titleLabel.repaint();
titleLabel.revalidate();
}
代码示例来源:origin: igniterealtime/Spark
/**
* Called when the Save-Button is pressed
* @param e
*/
private void savebuttonaction(ActionEvent e) {
try {
Color c = _colorpick.getColor();
_colorsettings.setColorForProperty(
(String) _colorliste.getSelectedValue(), c);
UIManager.put( _colorliste.getSelectedValue(), c);
_errorlabel.setText(Res.getString("lookandfeel.color.saved"));
} catch (Exception ex) {
_errorlabel.setText(Res.getString("title.error"));
_errorlabel.revalidate();
}
}
代码示例来源:origin: stackoverflow.com
label.revalidate(); // ADDED
代码示例来源:origin: stackoverflow.com
if(something) {
doSomething(myPanel);
}
public void doSomething(JPanel myPanel) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
Component[] components = myPanel.getComponents();
Component component = null;
for (int i = 0; i < components.length; i++) {
component = components[i];
if (component instanceof JLabel) {
JLabel label = (JLabel) component;
String name = label.getName();
if (name.equalsIgnoreCase("a")) {
label.setIcon(null);
label.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ImageA.jpg")));
label.revalidate();
label.repaint();
}
}
}
myPanel.revalidate();
myPanel.repaint();
}
});
}
代码示例来源:origin: stackoverflow.com
int w = img.getWidth();
int h = img.getHeight();
frame.setSize(w, h); // I just did that to make the example easier to understand
JLabel label = new JLabel(new ImageIcon(img)); // so your "background" label with the map image
// we need this dot label somewhere else and it must be final
final JLabel dot = new JLabel(new ImageIcon(redDot)); // and your dot label with the dot image as icon
label.add(dot);
frame.add(label);
label.setBounds(0, 0, w, h); // just for the example, the map-label is set to fill the frame
dot.setBounds(50, 50, 60, 60); // setBounds will handle both: location and size
frame.pack(); // pack will do all the stuff to make sure everything is painted and has the correct size when the window becomes visible
// and here comes the animation:
// my solution is to use a swing timer. Swing timers execute in a background thread and are perfectly suited to "update" any swing component without blocking the User Input thread.
// this timer will call the actionPerformed() of the ActionListener every 500 ms
Timer timer = new Timer(500, new ActionListener(){
@Override
public void actionPerformed(ActionEvent e){
Point location = dot.getLocation(); // get current location of the dot
dot.setLocation(location.x + 10, location.y + 10); // just set a new location 10 px further right and further down
dot.revalidate(); // revalidate, so the updated position will be taken into account when the dot label will get painted again
}
});
timer.start(); // start the timer and it will immediately start moving your dot on the img
内容来源于网络,如有侵权,请联系作者删除!