layout-manager

BoxLayout refuses to honor preferred size of JButton

好久不见. 提交于 2019-12-02 02:24:12
I have been working on a small project that is supposed to simulate a gambling game. Unfortunately, I ran into some odd issues while working with BoxLayout . To the best of my knowledge, LayoutManager s usually honor any component's preferred size. However, in the below code, BoxLayout does not. Here is my code thus far: import java.awt.*; import javax.swing.*; public class Main { public static void main(String[] args) { JFrame.setDefaultLookAndFeelDecorated(true); JFrame frame = new JFrame("Suit-Up"); frame.setContentPane(makeGUI()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame

Layout managers to set this specific layout in java

℡╲_俬逩灬. 提交于 2019-12-02 02:07:49
问题 I have this layout that I need to program for an assignment and this is the first time I have used layout managers in the GUI so I'm having problems getting the layout to match. I need your help I Have two tabs labeled Account creation and Account transfer (those are ok) what I need is to have the JLabel (Account ID) and the first text field in one line then the next JLabel (Amount) and text field in the line under the first. Under that needs to be the JButton Centered (Create an Account).

JButton.setBounds(x,y,w,h) doesn't seem to work

谁说我不能喝 提交于 2019-12-02 01:35:37
import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.SwingUtilities; public class SimpleExample extends JFrame { public SimpleExample() { setTitle("Simple example"); setSize(500, 500); setLocationRelativeTo(null); setDefaultCloseOperation(EXIT_ON_CLOSE); JButton jb = new JButton("TEST"); jb.setBorderPainted(true); jb.setBounds(5, 5, 1, 1); ---> This line add(jb); } public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { SimpleExample ex = new SimpleExample(); ex.setVisible(true); } }); } } Just creating a simple

Layout managers to set this specific layout in java

做~自己de王妃 提交于 2019-12-02 01:24:21
I have this layout that I need to program for an assignment and this is the first time I have used layout managers in the GUI so I'm having problems getting the layout to match. I need your help I Have two tabs labeled Account creation and Account transfer (those are ok) what I need is to have the JLabel (Account ID) and the first text field in one line then the next JLabel (Amount) and text field in the line under the first. Under that needs to be the JButton Centered (Create an Account). Lastly the JTextArea (No account) needs to be in a column to the right in the empty space separate from

Spacing between columns of JButtons

无人久伴 提交于 2019-12-02 00:56:40
问题 I am working on a simple GUI where there is an isle between the first two columns and the next two columns of JButtons. The code looks as follows: JPanel panel = new JPanel(new GridLayout(50, 4)); JScrollPane scrollable = new JScrollPane(panel); for (int row = 0; row < rows; row++) { for (int column = 0; column < columns; column++) { JButton button = new JButton("Row " + row + " seat " + column); panel.add(button); } } Current Look How do I add an isle in the middle between the first two and

When creating a BufferedImage from a JPanel (w/o a JFrame), can I also use a layout manager?

僤鯓⒐⒋嵵緔 提交于 2019-12-02 00:49:57
I am trying to create a BufferedImage from a JPanel, without using a JFrame. Yesterday, I was finally able to get the image to appear with help from this community (see below), but now I'm having some layout trouble. All of the components on the BufferedImage begin drawing at 0,0, instead of following the layout manager. Does anyone know of a solution for this problem? Yesterday's question: Can I create a BufferedImage from a JPanel without rendering in a JFrame? In the code below, the two labels will overwrite each other in the top left corner of the image. import java.awt.Color; import java

Centering JLabels inside JPanels

天大地大妈咪最大 提交于 2019-12-01 22:21:28
I'm making a score-keeping program, but I'm running into a problem. What I've tried to do is have a JPanel at the top that contains two JPanels, which, in turn, contains two team names. I'm confused as to why the two JLabels at the top of the program aren't centered inside of the JPanels they're contained in. import java.awt.*; import java.awt.event.*; import javax.swing.*; public class ScoreFrame extends JFrame { private static final Dimension SCREEN_SIZE = Toolkit.getDefaultToolkit().getScreenSize(); private static final int WIDTH = SCREEN_SIZE.width; private static final int HEIGHT = SCREEN

Java GUI button's label can't be seen

江枫思渺然 提交于 2019-12-01 22:14:28
I'm a second year student and I'm working on my OOP project (Calculator). I'm done with the functions of the numeric buttons and operators. Now I'm in the stage of re-arranging my buttons. At first, I just set my button size to (50,50), it works fine and its label is still visible, but when I decided to make it smaller (30, 30), its label turned into "..." instead. Here's the pic: And heres my code: lblEdit.setBounds(-138,-5,180,50); lblView.setBounds(-90,-5,180,50); lblHelp.setBounds(-40,-5,180,50); txt.setBounds(15,35,250,30); // text pane txt2.setBounds(0,330,100,20); blank.setBounds(15,80

Spacing between columns of JButtons

南笙酒味 提交于 2019-12-01 22:10:40
I am working on a simple GUI where there is an isle between the first two columns and the next two columns of JButtons. The code looks as follows: JPanel panel = new JPanel(new GridLayout(50, 4)); JScrollPane scrollable = new JScrollPane(panel); for (int row = 0; row < rows; row++) { for (int column = 0; column < columns; column++) { JButton button = new JButton("Row " + row + " seat " + column); panel.add(button); } } Current Look How do I add an isle in the middle between the first two and last two columns using java swing? Use two panels... You could use two panels (for the seats) and one

Alternative solution to null layout manager when absolute positioning is needed

橙三吉。 提交于 2019-12-01 21:39:59
Few months ago i read this Swing tutorial http://zetcode.com/tutorials/javaswingtutorial/resizablecomponent/ for understanding how implementing resizable components inside Swing. The tutorial tells about using a null LayoutManager in order to have the possibility of absolute positioning child components. In a discussion relative to another subject @Andrew Thompson pointed out that using null layout is a bad idea. This article http://download.oracle.com/javase/tutorial/uiswing/layout/none.html describe null layout manager as not desirable too, anyway it says that in certain situations the might