Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #38335

Re: Is there a method to update control size?

From Knute Johnson <nospam@rabbitbrush.frazmtn.com>
Newsgroups comp.lang.java.programmer
Subject Re: Is there a method to update control size?
Date 2018-06-03 15:02 -0500
Organization A noiseless patient Spider
Message-ID <pf1hhg$7n8$2@dont-email.me> (permalink)
References <7a7e726d-051d-4f17-93ac-3dabdde80894@googlegroups.com> <pep4b3$qnp$1@dont-email.me> <959c54c7-9fb9-4bba-93c9-6983553999bf@googlegroups.com> <pepk05$8ku$1@dont-email.me>

Show all headers | View raw


On 5/31/2018 14:55, Eric Sosman wrote:
> Even without the customized JLabel (aside: Why call all your
> classes "custom" classes?), there's no need to duplicate the focus
> management logic, the border-changing, or the border objects.  You
> can attach one focus listener to as many components as you like.
> 

I'm with you, I've used this for years with no trouble at all.

package com.knutejohnson.classes;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

/**
  * FocusListener to change the background color of a JComponent when it
  * acquires or loses the focus.
  */
public class ColorFocusListener extends FocusAdapter {
     /** Background color of component when it is in focus */
     private final Color in;

     /** Background color of component when it is not in focus */
     private final Color out;

     /**
      * Create a new {@code ColorFocusListener}
      *
      * @param in Color when component is in focus
      * @param out Color when component is not in focus
      */
     public ColorFocusListener(Color in, Color out) {
         this.in = in;
         this.out = out;
     }

     /**
      * Changes the background color when focus is gained
      *
      * @param fe the {@code FocusEvent}
      */
     public void focusGained(FocusEvent fe) {
         JComponent c = (JComponent)fe.getSource();
         c.setBackground(in);
     }

     /**
      * Changes the background color when focus is lost
      *
      * @param fe the {@code FocusEvent}
      */
     public void focusLost(FocusEvent fe) {
         JComponent c = (JComponent)fe.getSource();
         c.setBackground(out);
     }
}



-- 

Knute Johnson

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

Is there a method to update control size? Eric Douglas <e.d.programmer@gmail.com> - 2018-05-31 07:34 -0700
  Re: Is there a method to update control size? Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2018-05-31 17:20 +0200
  Re: Is there a method to update control size? Eric Sosman <esosman@comcast-dot-net.invalid> - 2018-05-31 11:28 -0400
    Re: Is there a method to update control size? Eric Douglas <e.d.programmer@gmail.com> - 2018-05-31 09:42 -0700
      Re: Is there a method to update control size? Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2018-05-31 19:22 +0200
        Re: Is there a method to update control size? Eric Douglas <e.d.programmer@gmail.com> - 2018-05-31 10:38 -0700
          Re: Is there a method to update control size? Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2018-05-31 19:45 +0200
            Re: Is there a method to update control size? Eric Douglas <e.d.programmer@gmail.com> - 2018-05-31 10:55 -0700
              Re: Is there a method to update control size? Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2018-05-31 20:05 +0200
                Re: Is there a method to update control size? Knute Johnson <nospam@rabbitbrush.frazmtn.com> - 2018-06-03 15:00 -0500
                Re: Is there a method to update control size? Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2018-06-04 02:25 +0200
      Re: Is there a method to update control size? Eric Sosman <esosman@comcast-dot-net.invalid> - 2018-05-31 15:55 -0400
        Re: Is there a method to update control size? Knute Johnson <nospam@rabbitbrush.frazmtn.com> - 2018-06-03 15:02 -0500

csiph-web