layout-manager

laying out components in GridBagLayout not as expected

瘦欲@ 提交于 2019-12-12 03:12:24
问题 import java.awt.*; import java.awt.event.*; import java.util.*; import javax.swing.*; public class GridBagLayoutDemo extends JFrame { private JFrame frame; private JPanel panel; private JLabel l1,l2,l3,l4,l5,l6,l7,l8; private JRadioButton r1,r2,r3,r4,r5,r6,r7,r8; private JTextField t1,t2,t3,t4; private JComboBox c1; GridBagConstraints gbc; GridBagLayout gbl; public static void main(String[] args) { new GridBagLayoutDemo(); } public GridBagLayoutDemo() { frame=new JFrame(); panel=new JPanel();

Java GroupLayout Exception

风流意气都作罢 提交于 2019-12-12 03:00:04
问题 public class Grouplayout implements Runnable { public static void main(String[] args) { SwingUtilities.invokeLater(new Grouplayout()); } @Override public void run() { JFrame jFrame = new JFrame(); GroupLayout layout = new GroupLayout(jFrame.getContentPane()); jFrame.getContentPane().setLayout(layout); layout.setAutoCreateGaps(true); layout.setAutoCreateContainerGaps(true); JLabel jLabel1 = new JLabel("a"); JLabel jLabel2 = new JLabel("b"); JLabel jLabel3 = new JLabel("c"); JLabel jLabel4 =

How do I make a JPanel item go under another item in the same BorderLayout?

ぃ、小莉子 提交于 2019-12-12 02:46:36
问题 I am trying to get my JTextField ( desc ) to under the JSpinner , ( dayspinner ) but I'm not sure how. If I put the text field in SOUTH , it just goes all the way to the bottom of the window. I would also like to implement whatever solution there is to this problem with my beginning menu with the 3 buttons next to each other, I would much rather them be on top of one another. import javax.swing.*; import javax.swing.event.*; import java.awt.*; import java.awt.event.*; public class Scheduler {

Absolute Layout Panel within JScrollPane

拜拜、爱过 提交于 2019-12-12 02:27:57
问题 I'am using panel with absolute layout (don't ask why) and I need to add elements on it programmatically. I done that part, but now I want to surround panel with JScrollPane so that when user add more items, scroll bar does its job. But surrounding panel with scroll bar doesn't work. What can I do here. JFrame frame = new JFrame(); frame.setSize(582, 451); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().setLayout(null);

Change panel size in flow layout

前提是你 提交于 2019-12-12 01:54:18
问题 I am developing a GUI form in java. In that I am adding two panels in main frame which has FlowLayout . But now I want to change the size of panels and I tried changing using setsize() , and I can see no difference. Here is my code: public class Main_window extends JFrame implements ActionListener { JFrame MainFrm = new JFrame("MCQ Generator"); JPanel LeftPanel = new JPanel(); JPanel RightPanel = new JPanel(); JButton BrowseButton = new JButton("Browse/Open"); TextArea ta1 = new TextArea();

Java Swing GUI doesn't seem

眉间皱痕 提交于 2019-12-12 01:42:53
问题 I'm trying to make a GUI based on BorderLayout and GridLayout by hand-writing not with a form builder. Because of that, I'm most likely skipping a part in the code. It is loaded but not seem. import java.awt.*; import java.awt.event.*; import java.io.IOException; import java.net.InetAddress; import javax.swing.*; import javax.swing.border.EmptyBorder; class PanelDemo { JButton jbtnUpArrowFirst; JButton jbtnDownArrowFirst; JButton jbtnUpArrowSec; JButton jbtnDownArrowSec; JButton

How do I resize a JScrollPane within a JFrame? And how do I read from a file in Java?

a 夏天 提交于 2019-12-12 01:09:13
问题 I have a song library, and I would like this selection list to only be on the left hand side of the window because I want to put other information about the song on the righthand side. I'm not sure how to change the size of JScrollPane , which is inside the JFrame . In this library, I want to be able to import the songs stored in a file to my song library. Right now, I have an array within my code, but I want to be able to read from a text file instead of using this approach. In the file, I

Switching Panels in Swing

元气小坏坏 提交于 2019-12-12 00:27:44
问题 I have a Swing application using Card Layout which basically changes the displayed panel depending on what the user selects from a drop-down menu. One of my panels has a form. I would need for when the submit buton is pressed for all the inputs to be collected and the Panel to be switched to another one. (This second panel is defined in a separate class) I would also need for all the input to be somehow passed to a method in the new panel. Any suggestions? Dario 回答1: If you look at the <-- s

Aligning components in Box

邮差的信 提交于 2019-12-11 22:58:04
问题 edit: if you downvote this question, you may leave a comment to explain why, that will be more constructive. I obtain this unexpected result... ... using this code: import javax.swing.Box; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.SwingUtilities; public class TestAlignment extends JFrame { // Constructor public TestAlignment() { super("Test Alignment"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Components to show JLabel

Adding a JLabel in relative position to buttons

我的梦境 提交于 2019-12-11 18:14:44
问题 OK, this is the relative code I have so far. for (int i = gameLines - 1; i > 0; i--) { for (int j = 0; j < i; j++) { JButton jButton = new JButton(); jButton.setSize(buttonWidth, buttonHeight); jButton.setText("" + line[i].charAt(j)); int x = ((buttonWidth / 2 * gameLines + 1) - (buttonWidth / 2 * i) + (buttonWidth * j)); int y = (gameLines - (i + 1)) * buttonHeight; jButton.setLocation(x, y); panel.add(jButton); button[i][j] = jButton; button[i][j].setActionCommand(Integer.toString(i) + "."