layout-manager

How can I support scaling a view displayed in a JScrollPane to avoid displaying JScrollBars up to a minimum size?

[亡魂溺海] 提交于 2019-12-07 13:55:36
问题 The behavior I want to implement is to display a view at 1:1 scale by default. If its container is made larger (by the user dynamically resizing the parent JFrame) the view should be scaled to fit the larger area; if made smaller, the view should be scaled to fit the smaller area - up to a limit. When smaller than a minimum size, scroll bars should appear with a viewport to support navigating around the view which is displayed at its minimum scale. I have a poorly-functioning implementation

jpanel not displaying well with jframe set to gridbaglayout

帅比萌擦擦* 提交于 2019-12-07 09:47:04
问题 the program below is to position a jpanel at the top left conner of jframe with gridbaglayout but instead a very small box is displayed in center of jframe. when I set the layout of jframe to null, the jpanel displays fine. can someone tell me why the jpanel is compressed to the center of frame with gridbaglayout? i really need to use gridbag. please help import java.awt.*; import javax.swing.*; //swing package public class Major { //defining the constructor public Major() { JFrame maFrame =

Swing BoxLayout problem with JComboBox without using setXXXSize

拟墨画扇 提交于 2019-12-07 05:35:46
问题 here's an SSCCE: import java.awt.Color; import java.awt.Dimension; import javax.swing.Box; import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JPanel; public class BoxLayoutTest extends JFrame { public BoxLayoutTest(){ JPanel main = new JPanel(); main.setLayout(new BoxLayout(main, BoxLayout.Y_AXIS)); main.setBackground(Color.red); this.add(main); JPanel northPanel = new JPanel(); JPanel middle = new JPanel();

JScrollPane does not appear when using it on a JPanel

假如想象 提交于 2019-12-07 04:39:52
问题 I have been trying for hours to find a way to solve the issue, but I had no luck with that. Here is a sample code: import java.awt.BorderLayout; import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.SwingUtilities; public class Example extends JFrame { private static final long serialVersionUID = 1L; public Example() { JPanel contentPane = (JPanel) getContentPane(); contentPane

Are there Constraint Layout Managers on iPhone OS?

本秂侑毒 提交于 2019-12-07 02:27:20
问题 The CA Programming Guide is talking about Constraints Layout Managers. However, the CALayer in the iPhone SDK doesn't have any constraints property or addConstraint method. They say iPhone OS just doesnt provide custom layout managers. But how about the standard ones? 回答1: Unfortunately, despite the documentation saying so, even the springs-and-struts layout of layers is missing from the iPhone implementation of CALayer. This can be seen by the missing autoresizingMask property on CALayer on

How to layout? (JFrame, JPanel, etc.)

☆樱花仙子☆ 提交于 2019-12-06 15:31:10
I'm very new to Java Swing and Java overall (my class just got finished on Scanner and basics). I was taught only Swing basics which is "What is a JFrame..etc" and I'm stuck on how to layout or position things. On the image is the layout I desired and could anyone help and teach me how to code it? JFrame with, 5 JPanel components?(4 columns and the order form below) Additionally, when clicking the "CONFIRM" button, I would want a new window to popup. How would I be able to link multiple windows? A common strategy to solve complex computing tasks, is to break them into small, well defined

How to move JButtons and JLabels position in a JPanel, JFrame

此生再无相见时 提交于 2019-12-06 14:57:30
I am creating a simple lottery as a practice, I am a beginner of Java. I have achieved almost everything that I want apart from one thing: Moving the different texts and buttons to the position that I'd like them to be. Here is a picture edited in Photoshop describing how I would like it to be: The Lottery currently looks like this after you press the Play button: (As you can see the buttons get shifted to the right in order to make space for the text that is squished in to the left of the buttons) What I'm looking to achieve is for the buttons position to never move, and to put the text under

How can I replace one JPanel with another JPanel in the same position?

匆匆过客 提交于 2019-12-06 08:12:34
问题 I have a JFrame with about four frames. After a given action I want to replace one panel with another in the same position. My method for switching them looks like this (the this object is a class which extends JFrame ): public void switchPanel(){ mainPanel.remove(introPanel); mainPanel.add(questionPanel); this.repaint(); } The original creation of the window looks like this: mainPanel.add(titlePanel); mainPanel.add(sidePanel); mainPanel.add(introPanel); 回答1: You ask: How can I replace one

Which java swing layout should I use

旧巷老猫 提交于 2019-12-06 07:02:28
I need to create this frame: Which layout should I use? I am thinking about box or grid layout but then menu on the right will be a problem. There is a lot of repetition in your code. I would break down each section and make it a separate component and focus on it's individual layout needs. In you main screen you have 4 main areas (excluding the menu). I would use something like GridBagLayout to layout these 4 sections. This allows each section the ability to grow to it's required height, without effecting the others. You can also supply individual growth hints to each section as you see fit.

Fixed width, variable height in JPanel with flow

北城余情 提交于 2019-12-05 23:29:25
问题 I have an annoying problem with Java’s layout managers. I have the following situation: In a panel A are two other panels B with an absolute layout and C with a FlowLayout. B is highly customized and has a fixed size set via setPreferredSize . C should have the same fixed width as B but otherwise be of a variable height, depending on how many components are added in the flow. The resulting A should then have the fixed width and A.height + B.height as the height – at least that is what I want.