layout-manager

FlowLayout in Swing doesn't move to the next line

為{幸葍}努か 提交于 2019-12-11 17:54:25
问题 I'm using a flow layout inside a scroll panel. I keep adding button expecting them to add to the next line when there is no more available space, but they just keep adding. I want the scroll bar to only scroll vertically, not horizontally. My code: JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT, 6, 6)); for(int i = 0; i < 30; i++) panel.add(new JButton("asd")); 来源: https://stackoverflow.com/questions/50192589/flowlayout-in-swing-doesnt-move-to-the-next-line

Java component deployment using JPanel

試著忘記壹切 提交于 2019-12-11 17:37:17
问题 I wanted components deployment like this picture: I wrote a code that makes two JPanel in a JFrame and puts components JPanel on left side. I set Frame Layout to BorderLayout and Each panel's Layout to FlowLayout. However, result was not what I wanted. Even List is not appear. Result picture: Can you tell me what to do? There is a code below. package com.java.APISearch; import java.awt.*; import javax.swing.*; import javax.swing.JPanel; public class MainFrame extends JFrame { JPanel search;

Using JPanel to make a calculator: how to use layout?

纵然是瞬间 提交于 2019-12-11 16:21:50
问题 I'm working on a question that simply states to make an GUI that looks like This calculator, it doesn't have to function, just look like it. So I think I have the JPanel and JButton components right but I can't organize the fields to make it come out right. I'm pretty new so any crash course on how to organize a GUI would be appreciated. Here's what I have so far: // Using a JPanel to help lay out components. import java.awt.GridLayout; import java.awt.BorderLayout; import javax.swing.JFrame;

How to switch between JPanels in CardLayout?

泄露秘密 提交于 2019-12-11 12:57:26
问题 I have two JPanels that I want to switch between when user clicks on them. So I created a Window with a JFrame in it. Then I create a JPanel called cards and set its layout to CardLayout . Then I create two more JPanel s - these are the panels that I want to switch between - and I add them to cards . I add mouseClicked event listeners and I add cardLayout.next(cards) so the switch will happen. It doesn't work. Here's my code: public class Window { private JFrame frame; private JPanel cards;

How does JButton control it's size?

余生长醉 提交于 2019-12-11 12:43:43
问题 I have added a button to a frame and controlling it's text and/or minimum size with timer. I noticed, that button does grow sometimes, and sometimes does not. If in null layout, then it ignores both text and minimum width changing. If in FlowLayout layout, then it grows if text changing, but ignores minimum width changing. How make it grow in latter case? If minimum width changes, then why doesn't layout manager reshapes button? How to force it to reshape? Note: code below is SSCCE, i.e. it

JTextField not aligning in GridBagLayout

戏子无情 提交于 2019-12-11 11:44:07
问题 I've just started working with GridBagLayout , and the image below is pretty self-explanatory of the problem, I need the first JTextField of the first 4 rows to stretch all the way to the JLabel on the left, just like the right ones. The Component's grid widths, from top to bottom, are : 1, 1, 1, 1 1, 3 1, 1, 1, 1 1, 3 2, 2 2, 2 Code of the GridBagConstraints settings in the JFrame : Also, why even if I set anchor to 'NORTH', all the components still sit aligned at the center of the JPanel?

CardLayout: How to show panels in one class in the ActionListeners in another class?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-11 11:43:22
问题 I added my buttons in a JPanel (which has a border layout , added the buttons to its south position), then added another JPanel cardsPanel in the ( center position of the) parent panel, and gave it a CardLayout . I want this cardsPanel to be the container for the cards (I mean the panels which will share the same screen space). Now what I need to do is to to display those cards (I am calling the panels which will share the same screen space as cards) as a response to the buttons in the parent

Removing a JPanel from a JFrame, so slow

你离开我真会死。 提交于 2019-12-11 11:35:03
问题 This is what the code looks like: class Main extends JFrame { public MyPanel panel; public Main() { //all the frame init stuff panel = new MyPanel(this); Panel badPanel = new Panel();//this makes the remove method go veryy slow //add(badPanel, BorderLayout.SOUTH);// JPanel goodPanel = new JPanel(); add(goodPanel, BorderLayout.SOUTH); // this fixes the slowness of the remove method in calculate() add(panel, BorderLayout.CENTER); } public static void main(String[] args) { SwingUtilities

Cleaning up a Nested J panel

无人久伴 提交于 2019-12-11 11:24:53
问题 Rebuilt the SCCE for you guys. My goal is this The general idea is that clicking on the title bars of the menus (right side) will collapsible (set visible to false) the content panes associated with them: gender_panel_BG collapses gender_panel_body race_panel_BG collapses race_panel_body class_panel_BG collapses class_panel_body base_stats_panel_BG collapses base_stats_panel_body merits_panel_BG collapses merits_panel_body You get the idea Another thing that is bugging me is the huge space at

choosing the best Layout for this jframe

Deadly 提交于 2019-12-11 11:04:38
问题 plz can any one help me to choose the best Layout to make this window 回答1: I think BoxLayout is a good solution for your situation. You just provides the size of the frame and some gaps but not the components.I give it an assessment of each component. The x is 30 pixels. import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import java.awt.Font; import java.awt.GridLayout; import javax.swing.BorderFactory; import javax.swing.Box; import javax.swing.BoxLayout; import