layout-manager

Java GridBagLayout and JPanel Error: cannot add to layout: constraint must be a string (or null) [duplicate]

断了今生、忘了曾经 提交于 2019-12-13 06:27:06
问题 This question already has an answer here : getting Exception : java.lang.IllegalArgumentException: cannot add to layout: constraint must be a string (or null) (1 answer) Closed 6 years ago . I have researched this error and I cannot seem to find a solution. I am trying to create a grid of 800 JButtons with 40 columns and 20 rows. This will eventually be used to control a domino setting up robot I am making that will tip over dominoes. I have already successfully created a grid using

combine multiple windows to a single window

偶尔善良 提交于 2019-12-13 05:52:40
问题 I am developing an application which have the following windows If the information entered in the windows are correct than only the user will be prompted with the windows in the above sequence. Now the customer has demanded me with this user interface. Now I have to add all these windows in the last window format, with the specification's as the user will be allowed in the 2nd portion of the last image if the first information entered is correct.And the user when launches this app see the

how to add component in box layout on north of other and make them all anchor on south?

元气小坏坏 提交于 2019-12-13 02:57:50
问题 I try to make a very mini game. I have one JPanel , it uses a BoxLayout.Y_AXIS that contains three JLabel (name of JLabels = 1,2,3) I need a component inside that panel to anchor on South (so I use glue) The view result will be like this: 1 2 3 Then I have a JButton . If the user clicks the button, that JPanel adds a new JLabel (name of JLabel = neww) Here is the view result: 1 2 3 neww but I need something like this: neww 1 2 3 how should I do? Is it possible to handle it with BoxLayout ?

how to place last component of a jPanel on the right edge, even if the panel has a flowLayout Left

本秂侑毒 提交于 2019-12-13 02:57:18
问题 I have in my code : a jPanel with LEFT FlowLayout. It contains various components. see img: what i'm trying to implement: I'm trying to stick last component on the right edge of its panel container. See img: i tried: to add a Box.createHorizontalGlue before my last component, but it doesn't work as expected. The Code: Code has been created on purpose for the question and mirrors the original code logic: public class TheMotherPuckerGlue { public static void main(String [] a) { final JFrame

Java Swing components not showing

僤鯓⒐⒋嵵緔 提交于 2019-12-13 02:56:04
问题 Help me! Whenever I try to start up the code below, it shows only the button on the bottom and the password field everywhere else. I want to be able to see everything, but I can't public void setup(){ frame = new JFrame("Votinator 3000"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); voteconfirm = new JLabel(""); textarea = new JTextField(1); submit = new JButton("Submit Vote!"); chooser = new JList(items); password = new JPasswordField(1); password.setVisible(true); choices = new

BorderLayout setSize issue

微笑、不失礼 提交于 2019-12-13 00:25:27
问题 Before you come with GridBagLayout suggestions, I've tried that but I couldn't get it to work. I want a frame with the size 800 x 800 and with a center panel of 600x600. Right now, when I run it the center panel is 600x578. Can someone tell me where it goes wrong? It's just 22 pixels. public void createPlayground() { JFrame frame = new JFrame("ForFun Maze"); frame.setSize(WIDTH, HEIGHT); frame.setResizable(false); frame.setLayout(new BorderLayout()); JPanel buttonPanel = new JPanel();

Java Swing Add JPanel to JPanel

梦想与她 提交于 2019-12-12 20:25:25
问题 The Situation I am currently trying to build a 2D game with Java's Swing. For this, I have my main class Puzzle which is subclassing JFrame . To my frame I add my main JPanel which consists of several JPanel s added together (each of them being a new piece). EDIT 2: PlayingField is my model which will store the current location of each piece. One can select a piece with the mouse (the plan is to highlight it) and move it with the arrow keys as long as the next step (a full cell, so approx.

How do I nest layout managers without using swing classes/methods?

橙三吉。 提交于 2019-12-12 18:11:51
问题 I need to make an applet in Java 6, 640*480 pixels, with a toolbar on the bottom with some buttons, scrollbars, and labels. The best way I could think of was using a BorderLayout , making the BorderLayout.SOUTH region a GridBagLayout (which would contain the controls), and the rest of the BorderLayout area null, as a place for grapics to be drawn with the controls. I can't find any resources online that don't use swing, and I don't know anything about swing to deduce what they are doing or

Changing preferred size of a Swing component

时光怂恿深爱的人放手 提交于 2019-12-12 18:05:54
问题 I have a swing component where the ideal size of the component will vary based on the content that is is currently being displayed (which happens in this case to be an image). I'd like this preferred size to change when the content is changed, and also allow the layout to be changed (for example, if the component is being used inside a JScrollPane then the scroll extents would change to fit the size of the component). What is the canonical way to do this in Swing ? 回答1: Suggestions: Use a

Android's LinearLayout for Swing

旧时模样 提交于 2019-12-12 11:14:49
问题 Is there a LayoutManager for Swing that acts as LinearLayout in Android? I like an idea of components weights very much. 回答1: If you need individual weights use GridBagLayout. Or you can try BoxLayout. 回答2: You can use the FlowLayout, GridLayout or BorderLayout. In my experience in building GUI in java, I mostly use combinations of BorderLayouts (most of the time) and GridLayouts. Layout Basics If you want it to look like the code is: public void initComponents() { jButton1 = new javax.swing