Results 1 to 10 of 10
  1. #1
    VipinJain is offline Member
    Join Date
    Jan 2014
    Posts
    5
    Rep Power
    0

    Lightbulb Drawig Mask over the Panel

    I'm having a JFrame which has one JPanel .I want to put mask over the Panel till I fetch values from database to show Panel Busy .
    Any ideas .

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,965
    Rep Power
    8

    Default Re: Drawig Mask over the Panel

    Sounds like a job for a GlassPane?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    VipinJain is offline Member
    Join Date
    Jan 2014
    Posts
    5
    Rep Power
    0

    Default Re: Drawig Mask over the Panel

    Can u explain how to use it ???

  4. #4
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,965
    Rep Power
    8

    Default Re: Drawig Mask over the Panel

    Quote Originally Posted by VipinJain View Post
    Can u explain how to use it ???
    I could, but google does an even better job: https://weblogs.java.net/blog/alexfr...behaved_g.html
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    VipinJain is offline Member
    Join Date
    Jan 2014
    Posts
    5
    Rep Power
    0

    Default Re: Drawig Mask over the Panel

    I want the mask to be transparent , but by using glasspane we won't get it . And updating should not flickering.

  6. #6
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,965
    Rep Power
    8

    Default Re: Drawig Mask over the Panel

    Quote Originally Posted by VipinJain View Post
    I want the mask to be transparent , but by using glasspane we won't get it . And updating should not flickering.
    Nothing is stopping you from using transparency with a glasspane, and if you do it correctly, you shouldn't see any flickering.

    For more specific help, post an SSCCE demonstrating what you've tried.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  7. #7
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,236
    Rep Power
    7

    Default Re: Drawig Mask over the Panel


  8. #8
    VipinJain is offline Member
    Join Date
    Jan 2014
    Posts
    5
    Rep Power
    0

    Default Re: Drawig Mask over the Panel

    I am trying to draw mask (Loading ) over the screen while values are being fetched from database . I want the values are populated in the text box while having the mask over the screen . But when value in the text box is set it looses dimmer . Can I avoid that ? I have attached My code below -
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;

    import javax.swing.JButton;
    import javax.swing.JComponent;
    import javax.swing.JFrame;
    import javax.swing.JLayer;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
    import javax.swing.plaf.LayerUI;

    public class AppScreen extends JFrame {

    private static final long serialVersionUID = 1L;

    JTextField tf;
    JButton fill;
    JPanel mainPanel;
    JFrame currentFrame;

    public AppScreen() {
    init();
    addHandler();
    render();
    }

    private void init() {
    tf = new JTextField(25);
    fill = new JButton("Fill");
    mainPanel = new JPanel();
    currentFrame = this;
    }

    private void render() {
    mainPanel.add(tf);
    mainPanel.add(fill);
    LayerUI<JComponent> layerUI = new WallpaperLayerUI();
    JLayer<JComponent> jlayer = new JLayer<JComponent>(mainPanel, layerUI);
    this.add(jlayer);
    this.pack();
    this.setVisible(true);
    this.setSize(500, 300);
    this.setLocation(
    getToolkit().getScreenSize().width / 2 - this.getWidth() / 2,
    getToolkit().getScreenSize().height / 2 - this.getHeight() / 2);
    this.setDefaultCloseOperation(EXIT_ON_CLOSE);
    }

    private void addHandler() {
    fill.addActionListener(new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) {
    new Thread(new Runnable() {

    @Override
    public void run() {
    WallpaperLayerUI.busy = true;
    currentFrame.repaint();
    try {
    Thread.sleep(5000);
    } catch (InterruptedException e1) {
    e1.printStackTrace();
    }
    tf.setText("This is a demo");
    try {
    Thread.sleep(1000);
    } catch (InterruptedException e1) {
    e1.printStackTrace();
    }
    currentFrame.repaint();
    WallpaperLayerUI.busy = false;
    }

    }).start();
    }
    });
    }

    }


    import java.awt.AlphaComposite;
    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.RenderingHints;

    import javax.swing.JPanel;

    public class MyPanel extends JPanel{

    /**
    *
    */
    private static final long serialVersionUID = 1L;
    boolean busy ;

    @Override
    public void paint(Graphics g) {
    Graphics2D g2d = (Graphics2D) g;
    super.paint(g);
    g2d.setComposite(AlphaComposite.getInstance(
    AlphaComposite.SRC_OVER, 0.3f));
    g2d.setColor(Color.yellow);
    g2d.fillOval(0, 0, 120, 60);
    }

    }


    public class Test {

    public static void main(String[] args) {
    new AppScreen();
    }
    }

  9. #9
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,965
    Rep Power
    8

    Default Re: Drawig Mask over the Panel

    When posting code, please use the code tags to preserve formatting.

    Have you tried the links you've already been given? What worked about them? What didn't work about them?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  10. #10
    VipinJain is offline Member
    Join Date
    Jan 2014
    Posts
    5
    Rep Power
    0

    Default Re: Drawig Mask over the Panel

    I have tried that was not working . Earlier somebody asked for code that's why I have put code.

Similar Threads

  1. Drawig images.
    By vastrolorde in forum New To Java
    Replies: 2
    Last Post: 12-27-2013, 06:54 PM
  2. BufferedImage red mask
    By Szinek in forum AWT / Swing
    Replies: 0
    Last Post: 06-06-2013, 09:11 PM
  3. ciruit drawig tool-interface
    By kapil1089theking in forum Java 2D
    Replies: 1
    Last Post: 11-05-2011, 09:13 PM
  4. Creating a mask for animation
    By micah11 in forum New To Java
    Replies: 2
    Last Post: 10-25-2010, 04:31 AM
  5. How to mask password characters
    By Roselicious in forum New To Java
    Replies: 4
    Last Post: 04-16-2010, 02:26 AM

Posting Permissions

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