layout-manager

Why does the first panel added to a frame disappear?

∥☆過路亽.° 提交于 2019-11-26 01:09:31
问题 Below is an example of adding two panels to a frame. Only one panel (the 2nd, red panel) appears. Why does the first panel disappear? import java.awt.*; import javax.swing.*; import javax.swing.border.EmptyBorder; public class DisappearingPanelInFrame { DisappearingPanelInFrame() { JFrame f = new JFrame(this.getClass().getSimpleName()); f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); f.add(new ColoredPanel(Color.GREEN)); f.add(new ColoredPanel(Color.RED)); f.pack(); f.setVisible(true); }

Only one component shows up in JFrame

南楼画角 提交于 2019-11-26 00:49:08
问题 As an improvement to my encryption project I decided to make a little GUI. However, when I run the program, only the top element shows up on the screen and it appears to obscure the others, though I have no way of checking. Does anyone know why? Below is my code in its entirety besides e() and d() because those simply encrypt a string and have nothing to do with a GUI. I would also like a way to speed it up as much as possible without editing the encryption, just to make it as great as

How do I change JPanel inside a JFrame on the fly?

泪湿孤枕 提交于 2019-11-26 00:38:13
问题 To put it simple, there\'s a simple java swing app that consists of JFrame with some components in it. One of the components is a JPanel that is meant to be replaced by another JPanel on user action. So, what\'s the correct way of doing such a thing? I\'ve tried panel = new CustomJPanelWithComponentsOnIt(); parentFrameJPanelBelongsTo.pack(); but this won\'t work. What would you suggest? 回答1: Your use case, seems perfect for CardLayout. In card layout you can add multiple panels in the same

How to use CardLayout with Netbeans GUI Builder

喜你入骨 提交于 2019-11-26 00:38:07
问题 Preface (this is a self-answer post) I\'ve gotten my feet wet with Netbeans GUI Builder but I am just not starting to dive in to it to learn the more intricate details. I really didn\'t even know hot to change layout manager from the design view, I would just hand code it. So I tried asking the Google help desk by asking \"How to use different layout managers in Netbeans GUI Builder\" and surprisingly found zilch in the first couple pages of the results. In Eclipse Window Builder, from the

Why is it frowned upon to use a null layout in Swing?

老子叫甜甜 提交于 2019-11-25 22:15:22
问题 Recently, I started creating a program for the company I work for. Just as background info, I\'m still a student and a beginner programmer, so my solution is probably not recommended and I didn\'t know how to do it otherwise, but it works and I\'m not going to be judged for it because it\'s a student job totally unrelated to programming. The thing about the program is, it\'s going to be run on multiple different computer with different screen sizes and resolutions (800x600 and up). To make

Making a robust, resizable Swing Chess GUI [closed]

∥☆過路亽.° 提交于 2019-11-25 21:54:57
问题 How would I go about making this resizable Chess GUI? Our company has been tasked with making a Chess game. It needs to work on Windows, OS X and Linux/Unix machines, and we have chosen Java to achieve this, while maintaining a common code-base (handy for both maintenance, and keeping costs down). My task is to create the GUI. The User Design Team has cleared the following spec. with the client. The chess game (Chess Champ) will be robust to resizing and straightforward, it includes: A tool

Add a complex image in the panel, with buttons around it in one customized user interface

拜拜、爱过 提交于 2019-11-25 21:38:52
问题 How can i have this image like below into the slavePanel and on top of that JPanel adjust the JButtons which looks like the image but having buttons correctly wrapped around? (Right now they are shaped in 1 row, 4 column) // // Shot Gun mover up/down/left/right, middle on is for zoom // public void GunMover(JPanel configPanel) throws IOException { // Master Panel - holds everything JPanel masterPanel = new Panel(); masterPanel.setLayout(new SpringLayout()); // Slave Panel - with image

Providing white space in a Swing GUI

本秂侑毒 提交于 2019-11-25 21:29:54
问题 A GUI with no white space appears \'crowded\'. How can I provide white space without resorting to explicitly setting the position or size of components?­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­