layout-manager

Centering a JLabel in a JPanel

﹥>﹥吖頭↗ 提交于 2019-11-26 20:39:31
问题 I have a panel derived from JPanel . I have a custom control derived from JLabel . I am attempting to center this custom JLabel on my panel. The only way I know to do this that will work is to use the a null layout ( setLayout(null) ) and then calculate the custom JLabel's setLocation() point so that it's in the right spot. The custom JLabel is physically moved from one panel to this panel in this app and I believe the location previously set in setLocation is affecting things. However when I

LinearLayoutManager setReverseLayout() == true but items stack from bottom

不想你离开。 提交于 2019-11-26 20:23:04
This seems like it would be an easy solution, but it seems that setting private RecyclerView mRecyclerView; private RecyclerView.Adapter mAdapter; private LinearLayoutManager mLayoutManager; .... // More code mRecyclerView = (RecyclerView) rootView.findViewById(R.id.recycler_view); // Add item decoration mRecyclerView.addItemDecoration(new SpacesItemDecoration(DIVIDER_SPACE)); // use this setting to improve performance if you know that changes // in content do not change the layout size of the RecyclerView mRecyclerView.setHasFixedSize(true); // use a linear layout manager mLayoutManager = new

Put a JButton in the center of the screen with BorderLayout

依然范特西╮ 提交于 2019-11-26 18:38:17
问题 How to add a JButton into the center of a JFrame with BorderLayout() ? I tried using BorderLayout.CENTER , but instead of the center of the screen, it gave the top-center of the screen. Or do I have to use another layout manager? 回答1: Put a JPanel in the CENTER and set the layout to GridBagLayout or BoxLayout as seen in this answer to Set component at center of the page. The GridBagLayout is used to center a label containing the yellow/red gradient image seen in the Nested Layout Example. 回答2

Positioning components in Swing GUIs

戏子无情 提交于 2019-11-26 16:38:21
问题 I have some questions on positioning components and some questions on text fields and text areas (Java Swing). Any help is greatly appreciated. Right now I am trying to have two text fields beside each other with a different label above each describing what that text field does. To achieve this I have placed them in a GridLayout(2, 2) . Is this the best way? It is the only way I know to have a label directly over another component. Is there a better way? What about if there is just one label

JPanel positions and sizes changes according to screensize

北城余情 提交于 2019-11-26 15:31:37
The program runs with its size according to screen resolution or size of the computer. When I run it in a computer with specific size of its monitor it will change accordingly. My problem is the positioning and size of a JPanel, or any object inside the frame, to adopt on the change of screen size. So whenever I will present my program on any monitor with different sizes the components will still be organized and placed as what I've originally designed it. But here I'm testing it with one JPanel named displayMenu. In which it displays a panel colored in green. package saves.project; import com

Why does this GridBagLayout not appear as planned?

自作多情 提交于 2019-11-26 14:55:55
问题 I was trying to achieve the end result required in Setting an arbitrary width in GridBagLayout. For easy reference, here it is: This is the current result: Button number and row is shown in the form 1,1 , followed by the number of columns (2) declared for this cell. As you can see, it starts with buttons 1,1 (3) and below it 1,2 (4) being the same width, while declaring different numbers of columns. Can anyone determine how to correct the code? The current code: import java.awt.*; import

How to locate JLabels to an absolute position on Java GUI

吃可爱长大的小学妹 提交于 2019-11-26 14:43:32
问题 I have many JLabel s (which includes ImageIcon s) in a JPanel . And this JPanel is only a panel on the GUI; there are lots of other panels. I want to place labels to the exact pixel coordinates on their JPanel container. How can I do that without using GroupLayout ? 回答1: See Doing Without a Layout Manager (Absolute Positioning) in the Java tutorials. Creating a container without a layout manager involves the following steps. Set the container's layout manager to null by calling setLayout(null

How to right-justify icon in a JLabel?

六眼飞鱼酱① 提交于 2019-11-26 14:42:58
问题 For a JLabel with icon, if you setHorizontalTextPosition(SwingConstants.LEADING) , the icon is painted right after text, no matter how wide the label is. This is particularly bad for a list, as the icons would be all over the place depending on how long the text is for each item. I traced the code and it seems to be that in SwingUtilities#layoutCompoundLabelImpl , text width is simply set to SwingUtilities2.stringWidth(c, fm, text) , and icon x is set to follow text without considering label

Create a Chess board with JPanel [duplicate]

假如想象 提交于 2019-11-26 14:08:37
问题 This question already has an answer here: Making a robust, resizable Swing Chess GUI [closed] 2 answers I have a simple Chess board in a JPanel with GridLayout(8,8) as layout manager. I am trying to add panels for the fields' column name and row number. Right now I've created another panel with BorderLayout as layout manager, and in this panel I add the board in BorderLayout.CENTER . Next to the board itself I've added a panels with GridLayout(0,8) in BorderLayout.SOUTH and a panel with

Eclipse WindowBuilder, overlapping JPanels

百般思念 提交于 2019-11-26 12:33:17
I'm attempting to overlap JPanel instances. Put a panel directly on another, in the exact same position and exact size. Every time I do this it moves the other panel to the other side or underneath, the previous panel is inside another much larger one and has buttons in it. How would I do this? Keep in mind it's using the Window Builder tool. You might also want to look at OverlayLayout , seen here . It's not included in the conventional gallery , but it may be of interest. import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import javax.swing.JFrame; import javax