layout-manager

How to position components in a JFrame?

杀马特。学长 韩版系。学妹 提交于 2019-12-11 07:30:18
问题 jframe = new JFrame("Admin"); jpanel = new JPanel(); jpanel.setLayout(new FlowLayout()); jframe.add(jpanel); userLabel = new JLabel("Username:"); jpanel.add(userLabel); userLabel.setBounds(100, 100, 30, 30); userTxtfield = new JTextField(15); jpanel.add(userTxtfield); passwordTxtfield = new JTextField(15); jpanel.add(userTxtfield); jpanel.add(passwordTxtfield); passwordLabel = new JLabel("Password:"); jpanel.add(passwordLabel); userLabel.setBounds(100, 100, 30, 30); loginButton= new JButton(

Button and Textbox alignment in a jtable cell

不打扰是莪最后的温柔 提交于 2019-12-11 06:46:46
问题 I have a table which has both button and text box in some cells. Now I am able to put both the components in the table cell. Thanks for OscarRyz's code. Now my problem is I have to align these components such that the button is to extreme right of the cell and text box should start from the extreme left of the cell to the start of the button. (In simple, they should be adjacent to each other and occupy entire cell.) How can I align them inside the cell? Currently it looks like this, But what

how to use setLocation to move componets

丶灬走出姿态 提交于 2019-12-11 06:34:07
问题 I'm trying to set the components of this application to a set location using setLocation so far i haven't been able to move the components. There is more code but its get calling and setting this code for the most part. any ideas? import javax.swing.*; public class HangmanPanel extends JPanel { private static final long serialVersionUID = -5793357804828609325L; public HangmanPanel(){ JLabel heading = new JLabel("Welcome to the Hangman App"); JButton Button = new JButton("Ok"); //Button

Adding a JLabel to a Panel - how to layout the components properly?

倾然丶 夕夏残阳落幕 提交于 2019-12-11 05:53:14
问题 I want to put some words in the frame so I used panel1.add(new JLabel("Hello")); But there are some buttons which their sizes and positions are customized. I heard that we have to setLayout(null) for the button customizing and this is also making the label not showing up. (Not sure if it is because of this) What is the solution for this? 回答1: I'll point you to the Java tutorials for laying out components - they give a good introduction to Swing formatting and layouts. Rather than calling

jFrame not opening correctly or showing contents

我的梦境 提交于 2019-12-11 05:47:53
问题 so I have a school project I need help on! So I am doing a 'task force schedule' app as my major project for this year (Grade 11, south africa) and I am stuck. I have an login system that logs into the database fine, then I have a "check in station" class called CheckIn which has a button that should open a table showing all the people working in a given station at that time if they are checked in. So far the table only pulls data from the database of everyone that is in the station,

Preventing Overlay Layout from shifting background image label

假装没事ソ 提交于 2019-12-11 05:29:18
问题 I have a JFrame with a panel on it with Overlay Layout because I want to set a JLabel with an image as the background and put stuff over top of it. I set the size of the frame equal to the size of the image and when I put only that on it fits perfectly, but if I add anything over top of it it shifts the image to the right by the width of the component that I add and cuts it off to the right. It does this even though the component isn't in the region that is shifted over. The component is to

How to work with a specific element in GridLayout?

删除回忆录丶 提交于 2019-12-11 04:43:39
问题 I have a problem adding an icon to a spesific element(grid?) in gridlayout. My gridlayout contains 64 "bricks" which is intended to work as a chessboard. My gridcode looks like this: ChessBoard public class SjakkBrett extends JFrame implements Config { public ChessBoard() { setSize(800,800); setLayout(new GridLayout(BRICKS/ ROWS, 0) ); for (int id = 0; id < BRICKS; id++) add(new Brick(id)); setVisible(true); } Config public interface Config { public int ROWS= 8; public int BRICKS= 64; } My

Errors when using GUI: IllegalStateException

ε祈祈猫儿з 提交于 2019-12-11 04:12:53
问题 I keep getting errors when trying to run my program even though when making the program in net beans I have no errors. It's only when I try to compile that 50 errors pop up. Someone explained that my JTextField wasn't attached to the Horizontal group and I thought I fixed it but it seems not. public class TrianglePerimeter extends javax.swing.JFrame { public TrianglePerimeter() { utilizeComponents(); } @SuppressWarnings("Not Checked") private void utilizeComponents() { sideOneInput = new

which layout manager would be appropriate to my design?

社会主义新天地 提交于 2019-12-11 03:45:13
问题 I am a beginner to Java. I would like some help in Swings to position my components. I am not able to decide as which layout manager should I use to position my components in the following order +-----------------------------------+ | | | Username Text Field | | Password Password Field | | | | Submit button | | | +-----------------------------------+ The following is my code package ssst; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax

Writing a JPanel subclass that will obey GridBagLayout?

别说谁变了你拦得住时间么 提交于 2019-12-11 03:28:37
问题 I built a class that extends JPanel , and I have been setting a size on it every time. But now I need multiple instances of that JPanel sub-class to exist on another panel. I am using GridBagLayout , but my components disappear when I resize the Frame or take away the setSize(800,100) from the JPanel subclass. How do I built components that will obey these layout managers ? I want my custom component to be able to fit to the size that the layout manager asks for. Here is my custom component