layout-manager

Can Components be added to groups in GroupLayout dynamically?

萝らか妹 提交于 2019-12-25 08:27:42
问题 Can Component s be added to groups in GroupLayout dynamically, after setHorizontalGroup() and setVerticalGroup() have been called, without resetting the layout? I'm working on the GUI to a project that will help students find the best way to put together their weekly class schedules. This involves inputting information regarding class times, etc., for an unknown number of classes. Of course, I can't just add an arbitrarily large number of forms for the user to put information into and say "no

JPanel and Java layout managers

那年仲夏 提交于 2019-12-25 08:16:53
问题 Having read over the internet about JPanel for a while I feel I still need clarification after reading it. My questions: What is JPanel mostly used for? Which layout manager is most flexible to use? How do you position components at certain areas using layout managers? I find it really difficult to position components at certain areas within the container using a layout manager. What layout manager do you recommend I use or do you have to use a mixture of different ones? 回答1: My first

How the pack() function behave when we explicitly set the location of the container?

帅比萌擦擦* 提交于 2019-12-25 06:38:39
问题 Here is the minimal example what problem I am facing in my main GUI design import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JButton; import javax.swing.BoxLayout; class GuiTester { JFrame mainFrame = new JFrame(); JPanel panel = new JPanel(); GuiTester() { JButton newButton = new JButton(); JButton continueButton = new JButton(); panel.setLayout(new BoxLayout( panel, BoxLayout.Y_AXIS)); panel.add(newButton); panel.add(continueButton); panel.add(new JButton()); panel

adding multiple buttons using JPanels

蹲街弑〆低调 提交于 2019-12-25 06:32:05
问题 I have created a simple compass program that moves the GUI box around the screen and I am now progressing on to adding NE, NW etc. This involves using JPanels as this allows multiple objects. My issue is that I've made 9 separate panels for the separate buttons but I have no idea how to add them to the JFrame as everything I do doesn't seem to work. Any ideas would be appreciated. import java.awt.*; import java.awt.event.*; import javax.swing.*; public class MovingCompassExtraJFrame extends

How do I arrange JPanels from top to bottom?

十年热恋 提交于 2019-12-25 04:05:20
问题 I'm currently self-studying Java. I'm learning Graphical User Interface(GUI) programming. I want JPanel s to be arranged from top to bottom in a JFrame .First of all,I have a JLabel added to the first JPanel . The second JPanel has 5 JRadioButtions . The third JPanel has a JButton and a JLabel . When the JButton is pressed,the JLabel in the 3 rd JPanel shows some text. I used BoxLayout ( BoxLayout.X_AXIS ) for all the JPanels and added all 3 of them into a JFrame which has FlowLayout() . Here

Java Swing GridLayout stretched?

一曲冷凌霜 提交于 2019-12-25 03:55:36
问题 So I have the following Java Code which produces what you see in the image. The layout is pretty much what I wanted except that the buttons are stretched to be equal size and fill. Is there anyway to avoid this without using GridBagLayout like other answers suggest? I tried setting the size of the panel inside to something smaller but it got stretched anyway. Code: //Set-up main window JFrame mainwindow = new JFrame(); mainwindow.setSize(500, 500); mainwindow.setTitle("Example"); //Add

How to Position a JLabel in the specified Layout?

百般思念 提交于 2019-12-25 03:18:19
问题 I am trying to position my Labels and Button on screen. I found an answer here to set label's Position using: label3.setHorizontalAlignment(SwingConstants.CENTER); label3.setVerticalAlignment(SwingConstants.CENTER); but there has been no effect in my code. Also, on changing my layout from Flow Layout to Border Layout, only one Jbutton [CLEAR] appears on the Screen. Can anyone help me rectify this? public class Corrected1 extends JFrame { public JTextField tf1; public JTextField tf2; public

How to make jLabels stay attached to the corners of a window form, despite resizing the form in java?

送分小仙女□ 提交于 2019-12-25 02:43:38
问题 I have 4 jLabels in my java program, which i placed in 4 corners I want them to stay there despite user resizing the window. I have written the code for the labels, but cannot seem to figure out how to keep them glued to each corner. here is my code for the jLabels JLabel label_1 = new JLabel(""); label_1.setEnabled(false); label_1.setBounds(0, 0, 19, 19); contentPane.add(label_1); JLabel label_2 = new JLabel(""); label_2.setEnabled(false); label_2.setBounds(0, 242, 19, 19); contentPane.add

How to determine the size of a JTextField?

房东的猫 提交于 2019-12-25 02:26:53
问题 I'm doing a program involving the Pythagorean theorem, and wanted to leave a triangle in the middle, with three JTextField around three sides of it. I did it, but the problem is that when I create the JTextField and add it to the desired container, it is immense. It is a very large white rectangle that when I click to enter, get a small letter. So, my question is: How can I change the size of this JTextField to decrease it and avoid unnecessary sizes? P.S:.'m Using Swing and AWT library for

JLabel positioning is not working

强颜欢笑 提交于 2019-12-24 19:43:08
问题 I need to position the JLabel in my JFrame . I created a label and wanted to set its position, but both setAlignment and setBounds do not work. The label stays all the time at the top of the panel and it does not move. import java.awt.GridLayout; import javax.swing.*; public class Start extends JFrame { //JLabel label1 = new JLabel("HELLO!"); //JLabel label2 = new JLabel("CHOOSE LANGUAGE:"); public Start() { super(); setSize(480, 360); setDefaultCloseOperation(EXIT_ON_CLOSE); setLayout(null);