Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

label over button causes button to not function

KonradZuseMar 31 2013 — edited Apr 3 2013
So I have this image I created as a png(unless there is a better transparent image format); however it created the image the same size as in photoshop. I found out this bit of code
         button.setStyle("-fx-background-color: transparent;"); 
so it made only my graphic show; however I cannot drag my group anymore, and the botton event encompasses a HUGE 500x500 area. So is there a way to fix either my image, or for the "Transparent clicks" to not register?








Edited by: KonradZuse on Mar 30, 2013 11:04 PM

At first I thought something broke with the transparency and the button, but then I realized the button is still registering while transparent... >(



Edited by: KonradZuse on Mar 31, 2013 11:11 AM


I first thought that the label's transparency wasn't working, but then realized that it did, and that when my button is under my label, the clicks are not registering. I tried to use label.setMouseTransparent(true); but that completely negates the point of me having it as my image to drag, but the button DOES register.




Basically I am creating a floating widget application that has a transparent label on top, with a button underneath.

The label has a point in the center where the button is set, with some additional parents covering the button a bit. Both were made as PNG's in photoshop(One was tried as a gif as well).


When the button area is pressed, nothing happens, and it counts it as the label for some reason. The label is transparent though, and when I remove the button from the root, I cannot click in the space, but for some reason when I put the button in there, the button was being counted as the label, and I could drag the application around just fine, and no button actions went off.

When I turned transparency off, I could see the button presses when I was outside of the "label's area" which was basically a 1 pixel column, on the left, that I had to click on; Otherwise it was as if it was all the label. I'm not too sure if other components act in the same way, but that is really strange.
 @Override 
    public void start(Stage stage) 
    { 
         
        this.stage = stage; 
        configureGroup(); 
        configureScene(); 
        configureStage(); 
        mouseEvents(); 
    } 

    public void button() 
    { 
        button = new Button("",new ImageView(button1)); 
        button.setStyle("-fx-background-color: transparent;"); 
        button.setLayoutX(-10); 
    } 

    public void label() 
    { 
                 
        labelB = new Label("", new ImageView(body1)); 
       // labelB.setMouseTransparent(true); 
} 

    public void configureGroup() 
    { 
        label(); 
        button(); 
             
         
         
        root = new Group(button,labelB,labelP,labelM,labelH); 
    } 

 public void configureScene() 
    { 
        scene = new Scene(root, 500,500,true); 
        scene.setFill(Color.TRANSPARENT); 
    } 
     
    public void configureStage() 
    { 
        stage.initStyle(StageStyle.TRANSPARENT); 
        stage.setTitle("Countdown Timer"); 
        stage.setResizable(false); 
       // stage.setHeight(SCENE_HEIGHT); 
        //stage.setWidth(SCENE_WIDTH); 
        stage.centerOnScreen(); 
        stage.setScene(scene); 
        stage.show(); 
    } 
    public void mouseEvents() 
    { 
        labelB.setOnMousePressed((MouseEvent me) 
      ->{ 
            x = me.getScreenX() - stage.getX(); 
            y = me.getScreenY() - stage.getY(); 

            me.consume(); 
        }); 
        labelB.setOnMouseDragged((MouseEvent me) -> 
        { 
            stage.setX(me.getScreenX() - x); 
            stage.setY(me.getScreenY() - y); 
            me.consume(); 
        }); 
         
         
        button.setOnMousePressed((event) 
        ->{ 
            button.setGraphic(new ImageView(button2)); 
            labelB.setGraphic(new ImageView(body2)); 
            event.consume(); 
          }); 
         

        button.setOnMouseReleased((event) 
        ->{ 
            button.setGraphic(new ImageView(button1)); 
            labelB.setGraphic(new ImageView(body1)); 
            event.consume(); 
          }); 
    } 
now as you can see I have tried to use the MouseTransparent on the label, which I can click the button, but that will set everything off to moving which it is the main part of my application.

I originally had the root.setMouseDragged and Pressed, so I figured maybe switching it to just the label would mean the root overrode everything, but nope it didn't work still.


I also want to know what the issue with the buttons are? I had to set my button transparent, because for some reason the picture was HUGE even when saved as transparent. My button, as well as the label, encompass a 500x500 area about, which doesn't get affected by the transparency, but still I'm not too sure why the button is a normal button, and then has the rest of the 500x500 space filled with a normal gray skin...

I've done buttons in swing, and I've never seen that before. When you set the button's "icon" it was just that, nothing more. Not too sure why the button is filling space when I don't want to.

Thoughts?


EDIT: I tried to put the transparent button on top of the transparent label and the button now encompasses the entire Group now.

To me it seems that FX is having issues with Transparency in general. When putting the transparent button, without transparency, it's a giant button, even though it should be completely transparent with just the graphic(Even though the saved file was 500x500 or whatever.

Next this seems to be even though we are setting the transparent button/label to be transparent again(instead of a big button or white background on the label) I believe it's thinking that it's transparent, but not transparent.

I.E., it thinks it still has that white background, and can now be dragged, and clicked as if that white background is there, but it's not the white background now, it's the button, or the label, and for some reason it seems to be changing the other component into itself.

I also believe that this has to do with the fact that the objects aren't made transparent to begin with. As I mentioned before in Swing I only had to save the file as transparent, set it as the icon, and it would just be the transparent icon, no extra button space, no nothing.(I haven't tried this exact example of placing a button over another transparent object, but it should work in both Swing and FX).

Thanks,

~KZ
Edited by: KonradZuse on Mar 31, 2013 11:38 AM

Edited by: KonradZuse on Apr 1, 2013 11:16 AM

Edited by: KonradZuse on Apr 1, 2013 11:16 AM

Edited by: KonradZuse on Apr 1, 2013 11:17 AM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 1 2013
Added on Mar 31 2013
7 comments
831 views