layout-manager

Incorrect position of Swing components

空扰寡人 提交于 2020-01-17 14:17:08
问题 I woud like to have button btn at the bottom of a JFrame . I have this in right side. Where is bug in my code? class MainClass extends JFrame { private JSplitPane splitPan=null; private void treePanel(){ DefaultMutableTreeNode nod=new DefaultMutableTreeNode("AAA",true); nod.add(new DefaultMutableTreeNode("abcd")); JTree tree=new JTree(nod); JScrollPane scroll=new JScrollPane(tree); splitPan=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,scroll,new JLabel("aaaaa")); splitPan.setSize(this

BorderLayout - child component remains visible after adding another component

 ̄綄美尐妖づ 提交于 2020-01-15 15:31:58
问题 I try to do the following thing: Add a component to a JFrame with a BorderLayout Add another component to the JFrame I would expect the new component to 'overwrite' the old component, since I'm using a BorderLayout . This works if I overwrite the old component before I call pack() . Now if I add the 2nd component after I call pack() , both components remain visible. Example: public class Test extends JFrame{ public Test(){ setLayout(new BorderLayout()); add(new JLabel("Quite a long text"));

Center JLabel in BorderLayout with a button at line end

妖精的绣舞 提交于 2020-01-15 12:32:53
问题 I have a header on a section of my swing layout, and I want to have text centered horizontally across the whole width of the section, but also have a button on only the right side. It should look like this: /------Same width------\ /------Same width------\ [------------------------]Text here[----------------[Button]] I am currently using a BorderLayout, with the text in the center and the button at the line end, but the text is centered not counting the button, as such: /----Same width----\ /

BorderLayout - Control height but not width

烂漫一生 提交于 2020-01-14 12:42:54
问题 I am relatively new to Java UI and would appreciate your help with a simple problem that I have. I have a JPanel of type BorderLayout . The CENTER part contains a combo box. As the outer frame is resized, the panel resizes (this is desired) and the width of the combo box changes (this is desired too). However, the height of the combobox is also changing as the panel is resized. This is not desired. How can I ensure that my combo box expands in width but not in height? I also have a button in

BorderLayout - Control height but not width

99封情书 提交于 2020-01-14 12:38:07
问题 I am relatively new to Java UI and would appreciate your help with a simple problem that I have. I have a JPanel of type BorderLayout . The CENTER part contains a combo box. As the outer frame is resized, the panel resizes (this is desired) and the width of the combo box changes (this is desired too). However, the height of the combobox is also changing as the panel is resized. This is not desired. How can I ensure that my combo box expands in width but not in height? I also have a button in

How to remove the padding between in the JPanel still using a flow layout?

大兔子大兔子 提交于 2020-01-13 08:06:47
问题 Here's the portion of my java application GUI that I have a question about. What this GUI consists is a blue JPanel(container) with default FlowLayout as LayoutManager that contains a Box which contains two JPanels(to remove the horizontal spacing or i could have used setHgaps to zero for that matter instead of a Box) that each contains a JLabel. Here's my code for creating that part of the GUI. private void setupSouth() { final JPanel southPanel = new JPanel(); southPanel.setBackground(Color

Java: single frame vs multiple frames

我的梦境 提交于 2020-01-13 04:18:29
问题 Think about the classic installation process, where you have a "next" button and when you click it the content of the window changes. To represent this situation I thought of two possible solutions: -when "next" is clicked destroy the current JFrame and create a new JFrame, maybe passing to his constructor useful information (e.g. actual window size, content inserted by the user in the current frame, ...) -when "next" is clicked remove all the components from the current JFrame and add new

How to make JTextArea Stick to the window

霸气de小男生 提交于 2020-01-11 09:58:10
问题 Hello I would like to make this TextArea stick to the windows size whene I resize it by mouse, the same way as lower buttons does. This is the code it is perfectly working no bugs, please have a glance at it. import java.awt.BorderLayout; import java.awt.Component; import java.awt.Container; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.GridLayout; import java.awt.LayoutManager; import javax.swing

FlowLayout in conjection with setBounds()

自闭症网瘾萝莉.ら 提交于 2020-01-07 01:21:08
问题 I have a JFrame . I use setBounds() for determine position and size, but when I use frame.setLayout( new FlowLayout() ) all components are cluttered. What is the solution? 回答1: 1) setBounds() is bad practice with null LayoutManager ( setLayout(null) ). 2) When you use FlowLayout , it calculates positions and sizes of components. So, you can't mixing 2 approaches. Examine how to use LayoutManager. 来源: https://stackoverflow.com/questions/25258318/flowlayout-in-conjection-with-setbounds

GridBagLayout erratic resizing and displaying

你说的曾经没有我的故事 提交于 2020-01-06 21:21:49
问题 I'm making a program that uses a GridBagLayout in a container. My primary use for this is to have two JPanels, which occupy 75% and 25% of the horizontal space of the window. For some reason though, the two panels look more like 90/10, and when resizing, the smaller one rapidly changes in size, between it's apparent minimum size, and what I believe is the desired 25%. Here is the relevant code. frmReedreadV = new JFrame(); frmReedreadV.setBounds(x, y, width, height); frmReedreadV