layout-manager

Complex layout of multiple components

隐身守侯 提交于 2021-01-29 05:29:28
问题 I am designing a GUI where I have the components shown below. But in the second row, I would like to manage spaces between the components. For example, in the second row, I would like to fit both the JLabel "Move to time" and the JTextField without so much spacing. As I can see, right now MigLayout places the JTextField in line with the second component in the first row. Then, the JButton "Move" in the 2nd row should be aligned to the 2nd component in the first row. How do I achieve this?

Layout - Relative to screensize

半腔热情 提交于 2021-01-29 04:41:19
问题 So I am a computer science student and I've finished my first year. I wanted to create a simple program and I realized that I am so tired of using no layout; this.setLayout(null); It is so tiresome to add bounds to every single component. Well, I have been using JPanel components and GridLayout a lot, which have made my work a bit easier. But I am tired of it. I care very much about the look of the GUI I make and use almost half the time programming to make the GUI look good before I start

How to display two canvas in a JFrame java

这一生的挚爱 提交于 2021-01-29 03:50:56
问题 I recently have a requirement to display a word file within a JFrame . With this link I was able to achieve what I want (Open MS documents into JFrame). What i need is to display a word file and a pdf file side by side within a JFrame. In the link mentioned above, the word file was displayed in a JFrame via a Canvas from SWT. I would like to know: Whether it is possible to add two canvases to a single JFrame . If not, is it possible to display a word document or a PDF file in a JPanel (since

JScrollPane doesn't top align when there is more than enough space to show the content

房东的猫 提交于 2021-01-28 04:27:29
问题 I have a JScrollPane that show a list of items. I would like the user to be able to scroll through the list if there is not enough space on the screen to show the list and I would like the list to align to the top of the available space if there is more than enough space to show the list. I can do one or the other but can't seem to get both to work. The code shown below accomplishes the goal of allowing the list to be scrollable if the list is larger than the available space but does not

How do I use GridLayout and multiple Panels?

為{幸葍}努か 提交于 2021-01-27 21:06:20
问题 How do I use multiple JPanel containers to make this code look like this? This is the image of what my code is supposed to be like but I cant figure it out. I can only use GridLayout , BorderLayout and FlowLayout . As a beginner, We've only been over basic concepts but I need more help. I am also not permitted to use GridBagLayout . I appreciate all the help. 回答1: A common strategy to solve complex computing tasks, is to break them into small, well defined manageable tasks. Divide and conquer

Java LayeredPane LayoutManager add() Method Conflict

我的梦境 提交于 2021-01-27 11:54:55
问题 Suppose I have a JLayeredPane called mainPanel that is using a BorderLayout . I also have a JLabel called backgroundLabel that contains an image. How would I go about adding the backgroundLabel to the bottom layer of mainPanel ? mainPanel.add(backgroundLabel, new Integer(-1), new Integer(0)); The above line seems like the obvious answer, and would work if the mainPanel was using a null layout. The BorderLayout in mainPanel is not liking the command and gives the following stack trace.

How can I move a table downward in Java?

元气小坏坏 提交于 2021-01-20 09:03:08
问题 Is it possible to move a table downward in Java. I tried setBorder , setLocation , ... but it didn't work. What should I do? JLabel label = new JLabel("Enter proper data: "); label.setBounds(0, 0, 120, 50); frame.add(label); JButton btn = new JButton("Click"); btn.setBounds(100, 300, 80, 50); frame.add(btn); String data [][] = new String [6][4]; String column[]={"No.","Player 1","Player 2","Strategy"}; JTable table = new JTable(data, column); JScrollPane sp=new JScrollPane(table); frame.add

This GUI is displaying nothing after setting BoxLayout

女生的网名这么多〃 提交于 2020-12-13 04:34:57
问题 import javax.swing.*; import java.awt.*; import java.awt.event.*; public class GUI_Borrower extends JFrame implements ActionListener { JPanel panel = new JPanel(); JLabel lblName = new JLabel("Name:"); JLabel lblProg = new JLabel("Program:"); JLabel lblId = new JLabel("Library ID: "); JLabel lblTitle = new JLabel("Add Borrower"); JTextField txtName = new JTextField(10); JTextField txtProg = new JTextField(10); JTextField txtId = new JTextField(10); static int counter = 19000; JButton

This GUI is displaying nothing after setting BoxLayout

末鹿安然 提交于 2020-12-13 04:34:25
问题 import javax.swing.*; import java.awt.*; import java.awt.event.*; public class GUI_Borrower extends JFrame implements ActionListener { JPanel panel = new JPanel(); JLabel lblName = new JLabel("Name:"); JLabel lblProg = new JLabel("Program:"); JLabel lblId = new JLabel("Library ID: "); JLabel lblTitle = new JLabel("Add Borrower"); JTextField txtName = new JTextField(10); JTextField txtProg = new JTextField(10); JTextField txtId = new JTextField(10); static int counter = 19000; JButton