layout-manager

What layout accepts percentages instead of values in swing?

别来无恙 提交于 2019-11-28 10:26:57
I need to create frame content based on their percentage of visual space they need. For example 20% for panel1,80% for panel2. what layout does this kind of layout management? in reduced form GridBagLayout , but with success for your requirement 80% - 20% import java.awt.*; import javax.swing.*; import javax.swing.border.*; public class BorderPanels extends JFrame { private static final long serialVersionUID = 1L; public BorderPanels() { setLayout(new GridBagLayout());// set LayoutManager GridBagConstraints gbc = new GridBagConstraints(); JPanel panel1 = new JPanel(); Border eBorder =

Java Swing JFrame Layout

柔情痞子 提交于 2019-11-28 09:15:53
I just wrote a simple code where I want a textfield and a button to appear on the main frame, but after running all I see is the textfield. If I write the code of the button after the textfield then only the button is displayed. Any idea why? JFrame mainframe=new JFrame(); mainframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); mainframe.setBounds(0,0,200,200); JButton jb=new JButton(); jb.setText("Leech"); mainframe.add(jb); JTextField link=new JTextField(50); mainframe.add(link); mainframe.pack(); mainframe.setVisible(true); Ibrahim Add your components to a JPanel and then add that panel

Positioning component inside card layout

元气小坏坏 提交于 2019-11-28 08:56:50
问题 I have a main frame where i want to display object of my NewUser class in center position using card layout.Here is my main class import java.awt.*; import java.awt.event.*; import javax.swing.*; public class CardLayoutDemo implements ItemListener { JPanel cards; //a panel that uses CardLayout final static String BUTTONPANEL = "Card with JButtons"; final static String TEXTPANEL = "Card with JTextField"; public void addComponentToPane(Container pane) { //Put the JComboBox in a JPanel to get a

How to add components to JDialog

安稳与你 提交于 2019-11-28 08:25:31
问题 d1=new JDialog(); d1.setSize(200, 100); t1=new JTextField(); t1.setBounds(10,10,40,20); d1.add(t1); I want to add components in JDialog such as TextField, Button... 回答1: 1) first create a Jpanel JPanel pan=new JPanel(); pan.setLayout(new FlowLayout()); 2) add the components to that JPanel pan.add(new JLabel("label")); pan.add(new JButton("button")); 3) create JDialog JDialog jd=new JDialog(); 4) add the JPanel to JDialog jd.add(pan); 回答2: You have to make sure you use no layout manager. d1

adding multiple jPanels to jFrame

拟墨画扇 提交于 2019-11-28 07:41:48
I want to add two jPanels to a JFrame side by side. the two boxes are jpanels and the outer box is a jframe I have these lines of code. I have one class called seatinPanel that extends JPanel and inside this class I have a constructor and one method called utilityButtons that return a JPanel object. I want the utilityButtons JPanel to be on the right side. the code I have here only displays the utillityButtons JPanel when it runs. public guiCreator() { setTitle("Passenger Seats"); //setSize(500, 600); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container contentPane = getContentPane();

GUI: how to properly set layout

痴心易碎 提交于 2019-11-28 06:50:05
问题 I'm having some issues with setting layouts. (Don't mind the sizes of the buttons, I just want to understand layouts properly). Here is the window that I want to make: Here is the window I tried: Here's my code: import javax.swing.*; import java.awt.event.*; import java.awt.*; class Grid extends JFrame { private JTextField t1; private JTextField t2; private JCheckBox c1; private JCheckBox c2; private JButton b1; private JButton b2; private JButton b3; private JPanel ButtonPanel1; private

Java setBounds not working with JPanel

爷,独闯天下 提交于 2019-11-28 04:45:46
问题 i am doing a small Gui in java. i am using setBounds methods to set the position of buttons etc on my JFrame , but problem is that when i use it with JPanel button is not visible on JFrame , and without JPanel its quite ok ,, see both the codes and please help me as i am beginner and facing these foolish problems . This one is working fine JFrame jframe = new JFrame("Working Fine"); jframe.setLayout(null); JButton jbutton = new JButton("Position Test"); jbutton.setBounds(0, 0, 100, 100);

How would I be able to achieve this expandable layout in Java? Flexible BoxLayout etc

蹲街弑〆低调 提交于 2019-11-28 04:44:36
问题 I would like to be able to have three JPanels p1 p2 and p3, and have them lay out like so: I have been playing around with FlowLayout, BoxLayout etc but I'm not really sure if I am heading in the right direction. I am quite new with Java so I don't know what does what if I'm quite honest. I like how BoxLayout works, resizing the panels, but I would like to be able to give it some sort of width attribute. I am not using a visual designer for this, this is my window code at the moment: private

java.awt.AWTError: BoxLayout can't be shared [duplicate]

不想你离开。 提交于 2019-11-28 02:51:36
问题 This question already has an answer here: BoxLayout can't be shared error 4 answers I have initialized MotePanel, Command Panel and LEDPanel before setting their Layout, then how so am I getting this exception. Please help. Exception in thread "main" java.awt.AWTError: BoxLayout can't be shared at javax.swing.BoxLayout.checkContainer(BoxLayout.java:462) at javax.swing.BoxLayout.invalidateLayout(BoxLayout.java:246) at javax.swing.BoxLayout.addLayoutComponent(BoxLayout.java:279) at java.awt

.setBounds not working for JLabel and JButton

对着背影说爱祢 提交于 2019-11-28 02:29:40
I am trying to change the positioning of a JLabel and a JButton on my GUI. Even though I try to use .setBounds to change their locations; they both just appear in the top centre of the screen. import java.awt.color.*; import java.awt.font.*; import java.awt.Graphics; import java.awt.Image; import javax.swing.*; import javax.swing.*; import java.awt.event.*; import java.awt.*; import javax.swing.UIManager.*; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; public class yo implements MouseListener { Image image; JButton button = new JButton("Wassup"); JFrame frame = new