Results 1 to 5 of 5
  1. #1
    kiltrosman is offline Member
    Join Date
    Jul 2015
    Posts
    3
    Rep Power
    0

    Question Java default properties in new component

    Java default properties in new component-java.png

    Hi, In the red square are three variables created by me, and I'm trying to create a default constructor, in a way that, when I righ-click on it, and look for its propierties it apear a default option, AND NOT "NULL" (Just like in the green circle).

    Could anyone help me please? :D

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Java default properties in new component

    Please post the java source code that you are having problems with. Be sure to wrap the code in code tags.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    kiltrosman is offline Member
    Join Date
    Jul 2015
    Posts
    3
    Rep Power
    0

    Default Re: Java default properties in new component

    package matrizfinal;

    import java.awt.BasicStroke;
    import java.awt.Color;
    import java.awt.Component;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.MultipleGradientPaint;
    import java.awt.RadialGradientPaint;
    import java.awt.RenderingHints;
    import java.awt.geom.Ellipse2D;
    import java.awt.geom.Point2D;
    import javax.swing.BoxLayout;

    /**
    *
    * @author Julian
    */

    public class LI extends javax.swing.JButton{
    private int DIAMETRO;
    private java.awt.Color colorApagado;
    private java.awt.Color colorEncendido;
    private java.awt.Color colorBorde;
    private java.awt.Color colorLED;
    private boolean estadoLogico;
    private Graphics2D g2;
    private Graphics g1;

    public LI(){
    inicializar();
    this.setcolorApagado(java.awt.Color.GRAY);
    this.setcolorEncendido(java.awt.Color.GREEN);
    setcolorBorde(java.awt.Color.YELLOW);

    colorLED = colorApagado;
    estadoLogico = false;
    }

    private void inicializar() {
    this.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
    }

    @Override
    public void paint(Graphics g) {
    g1=g;
    g2 = (Graphics2D) g1;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASIN G,
    RenderingHints.VALUE_ANTIALIAS_ON);

    if(getModel().isPressed()){
    if(estadoLogico){
    colorLED=colorApagado;
    estadoLogico=false;
    }else{
    colorLED=colorEncendido;
    estadoLogico=true;
    }
    }
    if(getModel().isRollover()){
    g2.setColor(colorBorde);
    g2.fillOval(0,0,DIAMETRO+6,DIAMETRO+6);
    }
    else{
    g2.setColor(colorLED.darker());
    g2.fillOval(1,1,DIAMETRO+4,DIAMETRO+4);
    }
    if(colorLED==colorEncendido){
    estadoLogico=true;
    }else{
    estadoLogico=false;
    }

    System.out.println(estadoLogico);
    Colorear();
    }

    public void Colorear(){
    g2 = (Graphics2D) g1;
    setDimensiones();
    Point2D center = new Point2D.Float(DIAMETRO*0.5f,DIAMETRO*0.5f);
    float radius = DIAMETRO*0.5f;
    Point2D focus = new Point2D.Float(DIAMETRO*0.75f,DIAMETRO*0.25f);
    float[] dist = {0.0f, 0.5f, 1.0f};
    Color[] colors = {colorLED.brighter(),colorLED,colorLED.darker()};
    RadialGradientPaint p =new RadialGradientPaint(center, radius, focus,dist, colors,MultipleGradientPaint.CycleMethod.NO_CYCLE) ;
    g2.setPaint(p);
    g2.fillOval(3,3,DIAMETRO,DIAMETRO);
    }

    public void setDimensiones(){
    if(this.getWidth()<this.getHeight()){
    DIAMETRO=this.getWidth()-6;
    }else{
    DIAMETRO=this.getHeight()-6;
    }
    }

    public void setDimensiones(int diametro){
    DIAMETRO=diametro;
    }

    public final void setcolorApagado(Color color){
    this.colorApagado=color;
    }

    public final void setcolorEncendido(java.awt.Color color){
    this.colorEncendido=color;
    }

    public final void setcolorBorde(java.awt.Color color){
    this.colorBorde=color;
    }
    }
    Last edited by kiltrosman; 07-12-2015 at 04:08 AM.

  4. #4
    kiltrosman is offline Member
    Join Date
    Jul 2015
    Posts
    3
    Rep Power
    0

    Default Re: Java default properties in new component

    That is the Java swing component. Java default properties in new component-java.png
    Add it to pallete, and look for it :3

  5. #5
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Java default properties in new component

    Assign a value to a variable if you don't want it to have the default value of null.

    Please edit your post and wrap the code in code tags.

    I'm not familiar with the tool shown in the images in your last post.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. setting component properties globally
    By amess in forum NetBeans
    Replies: 0
    Last Post: 11-23-2011, 11:12 PM
  2. Set default component's font
    By banhbaochay in forum NetBeans
    Replies: 8
    Last Post: 04-12-2010, 04:15 AM
  3. Replies: 1
    Last Post: 03-10-2009, 01:12 PM
  4. Swing - Changing component default font
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 03-11-2008, 10:52 PM
  5. how to use java.util.Properties?
    By christina in forum New To Java
    Replies: 2
    Last Post: 08-03-2007, 05:26 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •