layout-manager

Trying to teach myself Java GUI (Swing), should be an easy fix

。_饼干妹妹 提交于 2019-12-11 03:26:24
问题 Alright, like the title says, this should be an easy question but I'm very new to doing gui and I'm having a little problem. I'm trying to separate my window into 3 bordered sections (horizontal). So far I've got two, however, the one in the middle extends down to the bottom of the window, blocking the bottom section. I'm guessing it has something to do with my use of NORTH, CENTER, and SOUTH? I attached a picture of the window and some of my code, let me know if you need more! Top section

How to add a label to the extra space on a tabbed pane

喜夏-厌秋 提交于 2019-12-11 02:54:20
问题 I am trying to add a JLabel to the blank space of a JTabbedPane (to the right of the tabs and above the content panel). I was very close with this SSCCE (using MigLayout ): public static void main(String[] args) { try { UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e) { e.printStackTrace(); } JFrame frame = new JFrame(); frame.setLayout(new

Java Swing: problems with width

二次信任 提交于 2019-12-11 02:00:44
问题 I have problems with understanding the behavior of my application. I want to create a simple window ( 1000x700px ), divided into two parts ( 250px and 750px width respectively). I tried the following code: import java.awt.Color; import java.awt.Dimension; import java.awt.FlowLayout; import javax.swing.JFrame; import javax.swing.JPanel; public class Example extends JFrame { private static final long serialVersionUID = 1L; public Example() { this.setSize(1000, 700); this.setTitle("Example");

Automatic content resizing of JLayeredPane

我怕爱的太早我们不能终老 提交于 2019-12-11 01:28:00
问题 I'm trying to create an app with a JLayeredPane that scales automatically with the size of the parent JFrame (this is the easy part using BorderLayout as layout manager on the frame's content pane). The hard part is the fact that I want the content of the JLayeredPane to automatically resize with the JLayeredPane (and thus the JFrame too). In fact the functionality I want to achieve is a lot like the dockable console in Netbeans, that just like comes "on top" of the editor when clicked, and

Java Swing Gridlayout: Accessing Specific Coordinate

余生颓废 提交于 2019-12-10 23:23:23
问题 I'm creating a Java swing GUI and I have formatted a JPanel to use a GridLayout. I need to access a specific "box" (i.e. specific coordinate) of the grid, but I cannot see a way to do so. How can I do this? 回答1: You shouldn't depend on GUI code (the View) to give you information about program data (the model). The best solution would be to "know" which component is where from the start--maybe you should have a data structure (2D array?) that holds the components and is updated whenever

Layout for displaying panels dynamically with scroll bar

风格不统一 提交于 2019-12-10 18:32:58
问题 In java, I have been trying to create a panel that can accept other panels with a scroll bar. I tried using gridlayout, and this works fine, except for the fact that if I only add a few panels, it grows those panels to fit the size of the parent panel. I tried using flowlayout, but this makes the panels flow horizontally as there is a scroll bar. How do I make it so I can add panels to the parent panel starting at the top and make them always the same size(or their preferred size). Also, when

Switching between screens in Java swing

妖精的绣舞 提交于 2019-12-10 17:25:25
问题 I had build big application for my client in Android. The new project is to build the same app for PC in Java. So i have started developing with use of swing. When building in Android i use classes with activities that had content views and i could switch between activities. In java i have build multiple classes that extends JFrame and i wish to switch between them. What is the right way to to this? is this: new_class.setVisible(true); old_class.setVisible(false); the correct way? 回答1: The

GridBagLayout gridding not working

这一生的挚爱 提交于 2019-12-10 13:55:36
问题 I am trying to create the following GUI: but the GUI that I make is: What my grid looks like: image: THE GRIDLAYOUT FOR THIS I don't understand why I am getting this output since I have drawn a diagram to aid the code and it seems to work out. The method addComp adds adds the input component to the input panel at a given (x, y) position and at a given component width and height. Code: import javax.swing.*; import java.awt.*; public class GUIError extends JFrame { //initialise all the

Can components of a gridbaglayout fill parent frame upon resize?

谁说我不能喝 提交于 2019-12-10 12:54:38
问题 I've got a JFrame whose root JPanel is instantiated with a GridBagLayout . At runtime, the panel is populated with components based on some description, and the width, height and x,y coords are given in the description to be used with the gridwidth , gridheight , gridx and gridy fields in GridBagConstraints . The components themselves can be also be JPanel s with their own child components and GridBagConstraints , the GUI is described in a tree so Frame is populated recursively. The problem I

java JPanel How to fixed sizes

随声附和 提交于 2019-12-10 12:39:22
问题 I want to have a resizable panel, that always has the top green panel of a fixed depth. i.e. all changes in height should effect the yellow panel only. My code below is almost OK, except the green panel varies in size a little. How do I do this? Panel.setLayout(new BoxLayout(Panel, BoxLayout.Y_AXIS)); Panel.setAlignmentX(Component.LEFT_ALIGNMENT); JPanel TopPanel = new JPanel(); TopPanel.setPreferredSize(new Dimension(80,150)); TopPanel.setVisible(true); TopPanel.setBackground(Color.GREEN);