2017-03-24 13 views
0

私はゲーム用のグリッドペインに追加する色付きタイルのランダムな配列を持っています。現在のところ、タイルはトグルボタン以外の機能はありません。ここをクリック snippet.JavaFX - ボタンが表示されていないイメージボタン

私は嫌な青い背景のために謝罪します。問題をさらに明確にするために追加しました。

私のタイル画像はボタンに適用されています。私が望むのは、ボタンの境界線が存在しない(できれば)存在しないか、何とか消えることです。

自分のタイル画像をボタンとして見たいだけです。

私は、枠線、クリップ、不透明度などを使って試してみました...私は何も確定できません。すべての必要な輸入品があるとTileArrayでrandomlyPopulate方法は、他のクラスで呼び出されると仮定すると

...

Tile.java

public class Tile { 

/* ----- ATTRIBUTES ----- */ 

private TileColor color; 
private ImageView tileImg = new ImageView(); 
private ToggleButton tileButton = new ToggleButton(null, new ImageView()); 

// Constructor used in TileArray 
public Tile(TileColor t, ToggleButton b) { 

    color = t; 
    tileButton = b; 
} 

// Getter 
public ToggleButton getTileButton() { 

    return tileButton; 
} 

// The enumeration used to determine which color tile is being used 
// Much easier for debugging to see the color name 
enum TileColor { 

White, 
Black, 
Green, 
Red 
} 

TileArray.java

public class TileArray { 

/* ----- ATTRIBUTES ----- */ 

// Initialize the array of tiles 
public Tile[][] arrayOfTiles = new Tile[5][5]; 

private Image whiteTileImg = new Image("image/white_tile.jpg"); 
private Image blackTileImg = new Image("image/black_tile.jpg"); 
private Image greenTileImg = new Image("image/green_tile.jpg"); 
private Image redTileImg = new Image("image/red_tile.jpg"); 


// Method to randomly populate the array with colored tile objects 
// The if statements are intentionally specific, and not 1/4 for each 
// Approximates 11 white tiles, 9 black, 3 green and 2 red 
public void randomlyPopulate() { 

    for(int i = 0; i < arrayOfTiles.length; i++) { 

     for(int j = 0; j < arrayOfTiles.length; j++) { 

      double iRand = Math.random(); 

      if (iRand <= .44) { 

       // Assign an ImageView to the tile and adjust its size 
       ImageView view = new ImageView(whiteTileImg); 
       view.setFitWidth(90); 
       view.setFitHeight(90); 

       // Assign a white tile to the array index 
       arrayOfTiles[i][j] = new Tile(TileColor.White, new 
       ToggleButton(null, view)); 
      } 

      if (iRand > .44 && iRand <= .80) { 

       // Assign an ImageView to the tile and adjust its size 
       ImageView view = new ImageView(blackTileImg); 
       view.setFitWidth(90); 
       view.setFitHeight(90); 

       // Adjust the color of the black tiles 
       // Otherwise they are hard to distinguish 
       // JavaFX did not take well to my png 
       ColorAdjust adjustTileColor = new ColorAdjust(); 
       adjustTileColor.setBrightness(.14); 
       view.setEffect(adjustTileColor); 

       // Assign a black tile to the array index 
       arrayOfTiles[i][j] = new Tile(TileColor.Black, new 
       ToggleButton(null, view)); 
      } 

      if (iRand > .80 && iRand <= .92) { 

       // Assign an ImageView to the tile and adjust its size 
       ImageView view = new ImageView(greenTileImg); 
       view.setFitWidth(90); 
       view.setFitHeight(90); 

       // Adjust the color of the green tiles 
       // Otherwise they are hideous 
       // JavaFX did not take well to my png 
       ColorAdjust adjustTileColor = new ColorAdjust(); 
       adjustTileColor.setBrightness(-.35); 
       adjustTileColor.setSaturation(-.4); 
       view.setEffect(adjustTileColor); 

       // Assign a green tile to the array index 
       arrayOfTiles[i][j] = new Tile(TileColor.Green, new 
       ToggleButton(null, view)); 
      } 

      if (iRand > .92) { 

       // Assign an ImageView to the tile and adjust its size 
       ImageView view = new ImageView(redTileImg); 
       view.setFitWidth(90); 
       view.setFitHeight(90); 

       // Assign a red tile to the array index 
       arrayOfTiles[i][j] = new Tile(TileColor.Red, new  
       ToggleButton(null, view)); 
      } 
     } 
    } 
} 

ご協力いただきありがとうございます。大変感謝しています。

-Bagger

答えて

0

はあなたToggleButtonでこれを呼び出すようにしてください:

setPadding(Insets.EMPTY); 
+0

ああ!パディング!私はこれをやめようとしなかった....ありがとうございました。私は助けに感謝します。 – Psychobagger

関連する問題