前提・実現したいこと
現在、フレームを表示するプログラムで、フレーム内のベージュっぽい色のパネル(?)がずれて表示されてしまいます。そのため、背景色を変更しても背景色で埋め尽くされない状況です。
発生している問題・エラーメッセージ
えらーはありません。
該当のソースコード
java
1package org.ylib.base.swing; 2 3import java.awt.Color; 4import java.awt.Dimension; 5import java.awt.Point; 6import java.awt.Rectangle; 7import java.awt.event.ComponentEvent; 8import java.awt.event.ComponentListener; 9 10import javax.swing.JFrame; 11 12public class JylFrame extends JFrame implements ComponentListener 13{ 14 /** フレームのタイトルを示す */ 15 private String title = "frame"; 16 /** フレームの x 位置、y 位置を示す */ 17 private Point xy = new Point( 100, 100 ); 18 /** フレームの横幅、高さを示す */ 19 private Dimension widthHeight = new Dimension( 1280, 960 ); 20 /** フレームのサイズ変更可否を示す */ 21 private boolean resizable = false; 22 /** フレームの背景色を示す */ 23 private Color background = new Color( 0xff000000, true ); 24 25 public JylFrame() 26 { 27 super(); 28 initFrame(); 29 } 30 31 public JylFrame( boolean undecorated ) 32 { 33 setUndecorated( undecorated ); 34 new JylFrame(); 35 } 36 37 private void initFrame() 38 { 39 setfSize( widthHeight ); 40 setfLocation( xy ); 41 setfBackground( 0xff000000 ); 42// setfResizable( false ); 43 setDefaultCloseOperation( 3 ); // EXIT_ON_CLOSE 44 addComponentListener( this ); 45 } 46 47 public Color getfBackground() 48 { 49 return background; 50 } 51 52 public void setfBackground( int argb ) 53 { 54 setfBackground( new Color( argb, true ) ); 55 } 56 57 public void setfBackground( Color c ) 58 { 59 background = c; 60 61 getContentPane().setLocation( 0, 0 ); 62 getContentPane().setBackground( background ); 63 } 64 65 public Rectangle getBounds() 66 { 67 return new Rectangle( getfX(), getfY(), getfWidth(), getfHeight() ); 68 } 69 70 public void setfBounds( Rectangle r ) 71 { 72 xy = new Point( r.x, r.y ); 73 widthHeight = new Dimension( r.width, r.height ); 74 } 75 76 public void setfBounds( int fx, int fy, int fwidth, int fheight ) 77 { 78 xy.x = fx; xy.y = fy; 79 widthHeight.width = fwidth; 80 widthHeight.height = fheight; 81 82 setfLocation( getfX(), getfY() ); 83 setfSize( getfWidth(), getfHeight() ); 84 } 85 86 public Point getfLocation() 87 { 88 return xy; 89 } 90 91 public int getfX() 92 { 93 return xy.x; 94 } 95 96 public int getfY() 97 { 98 return xy.y; 99 } 100 101 public void setfLocation( Point p ) 102 { 103 xy = p; 104 } 105 106 public void setfLocation( int fx, int fy ) 107 { 108 xy.x = fx; xy.y = fx; 109 } 110 111 public void setfLocationOnCenter( int wWidth, int wHeight ) 112 { 113 int locationw = ( wWidth - ( widthHeight.width + 22 ) ) / 2; 114 int locationh = ( wHeight - ( widthHeight.height + 56 ) ) / 2; 115 116 setLocation( locationw, locationh ); 117 } 118 119 public boolean getfResizable() 120 { 121 return resizable; 122 } 123 124 public void setfResizable( boolean fresizable ) 125 { 126 resizable = fresizable; 127 128 setResizable( resizable ); 129 } 130 131 public int getfHeight() 132 { 133 return widthHeight.height; 134 } 135 136 public Dimension getfSize() 137 { 138 return widthHeight; 139 } 140 141 public int getfWidth() 142 { 143 return widthHeight.width; 144 } 145 146 public void setfSize( Dimension d ) 147 { 148 widthHeight = d; 149 150 getContentPane().setPreferredSize( d ); 151 pack(); 152 setfTitle( title ); 153 } 154 155 public void setfSize( int fwidth, int fheight ) 156 { 157 widthHeight.width = fwidth; 158 widthHeight.height = fheight; 159 160 setfSize( new Dimension( widthHeight.width, widthHeight.height ) ); 161 } 162 163 public String getfTitle() 164 { 165 return title; 166 } 167 168 public void setfTitle( String ftitle ) 169 { 170 title = ftitle; 171 172 String newtitle = title + " " + getfWidth() + "x" + getfHeight(); 173 setTitle( newtitle ); 174 } 175 176 @Override public void componentResized( ComponentEvent e ) 177 { 178 widthHeight.width = getWidth() - 22; 179 widthHeight.height = getHeight() - 56; 180 181 setfTitle( title ); 182 } 183 184 @Override public void componentMoved( ComponentEvent e ) 185 { 186 xy.x = getX(); xy.y = getY(); 187 } 188 189 @Override public void componentHidden( ComponentEvent e ){} 190 191 @Override public void componentShown( ComponentEvent e ){} 192} 193
java
1import org.ylib.base.swing.JylFrame; 2 3public class GameMain 4{ 5 public static void main( String[] args ) 6 { 7 JylFrame jf = new JylFrame(); 8 jf.setfResizable( true ); 9 jf.setfSize( 640, 480 ); 10 jf.setfLocationOnCenter( 1920, 1080 ); 11 jf.setVisible( true ); 12 } 13} 14
試したこと
Stackoverflowというサイトに同じような問題がありました。しかし、それとは違いスレッドは使用していません。
補足情報(FW/ツールのバージョンなど)
java8 windows10 です。
IDEは使用していません。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/10/13 06:06
退会済みユーザー
2018/10/13 17:02
2018/10/14 02:19