layout-manager

Span multiple columns with RecyclerView

风格不统一 提交于 2019-12-17 21:40:08
问题 So what I am trying to go for is having a staggered layout but the first item in the list needs to span two columns. The first two rows are also a fixed height. I have everything working except the first item spanning two columns. I am using the RecyclerView.Adapter with the StaggeredGridLayoutManager. Doesn't seem like it is out of the box functionality. I assume I can make a custom layout manager I'm just not sure where to start. I have tried searching but I can't find anything about how to

Java Swing JFrame Layout

心不动则不痛 提交于 2019-12-17 18:55:01
问题 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);

Java JPanel inside JScrollPane?

有些话、适合烂在心里 提交于 2019-12-17 16:32:58
问题 I have a JFrame, in this JFrame I have a JPanel that I draw on, this Panel can be any size and so I placed it into a JScrollpane to let me scroll when the panel is larger than the window screen size. Unfortunately does not work as I expected: Making the JFrame window smaller than the JPanel size does not show scroll bars The JScrollPane size now seems locked to the size of the JPanel I have added to it, where as before it resized to the bounds of it's JFrame window (it still kinda does this

Java, setting layout to null

痴心易碎 提交于 2019-12-17 14:57:18
问题 I have been using a null layout and I alot of people will say it shouldn't be done this way. Is there a better way? Some code as example: import javax.swing.*; public class Main{ public static void main(String args[]){ JFrame frame = new JFrame(); JPanel panel = new JPanel(); JButton button = new JButton("Click"); //JFrame, frame frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setResizable(false); frame.setSize(500, 500); frame.setLocationRelativeTo(null); frame.setVisible(true);

Clear components of JFrame and add new components

可紊 提交于 2019-12-17 07:41:29
问题 I have a JFrame , which have some options. When OK button is pressed i want the same JFrame to clear the contents and add new contents. I have tried it but the problem is new JFrame is popped out. What am I doing wrong? import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.IOException; import java.net.InetAddress; import java.net.UnknownHostException; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.*;

Looking for general method for GridBagLayout component creation

这一生的挚爱 提交于 2019-12-17 06:56:51
问题 I'm designing a GUI with 20 or so components: 10 labels, 4 text fields, 4 buttons, and 2 text areas. Using GridBagLayout seemed a great idea. But with all the instance variables required to do it by the book for each component (i.e., not reuse), a general method for adding components seemed a must. I really thought this could work: (Note: HORIZ is abbreviation for GridBagConstraints.HORIZONTAL; CENTER is abbreviation for GridBagConstraints.CENTER.) public static void addComponent(Container f,

Is MVC in Swing Thread Safe

不羁岁月 提交于 2019-12-17 03:42:08
问题 I'm trying to touch limits of MVC architecture in Swing, but as I tried everything all (from SwingWorker or Runnable#Thread ) are done on EDT my questions: is there some limits or strictly depends by order of the implementations (wrapped into SwingWorker or Runnable#Thread ) ? limited is if is JComponent#method Thread Safe or not ? essential characteristic of an MVC architecture in Swing, ? inc. Container Re-Layout ? note: for my SSCCE I take one of great examples by HFOE , and maybe by

Eclipse WindowBuilder, overlapping JPanels

狂风中的少年 提交于 2019-12-17 02:32:18
问题 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. 回答1: 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

New Line Between Swing Components

自作多情 提交于 2019-12-14 03:46:55
问题 I have tried searching multiple time on how to format java swing elements multiple times, but I can't seem to find anything. I have tried to learn the grid bag layout but it is all too complicated. Could someone please tell me how to space swing components with Swing? Thanks! EDIT Code: import javax.swing.*; import java.awt.*; public class Format_Swing_Elemnts { public static void main(String[] args) { JLabel title = new JLabel("Bridge Settings:"); title.setFont(font); JLabel l1 = new JLabel(

How to add jpanel to a specific cell of GridLayout

余生长醉 提交于 2019-12-14 03:33:56
问题 in the below code, i created a GridLayot with 3 rows and 3 columns, what i want to do is,,to add jpanel_1 into a specifc cell of the Gridlayout, lets say in the grid cell number (2,3). Code : private void setUpGUI2() { // TODO Auto-generated method stub jFrame_2 = new JFrame("Border Demo"); GridLayout gridLayOut = new GridLayout(3,3); jFrame_2.setLayout(gridLayOut); jPanel_1 = new JPanel(new BorderLayout()); jPanel_2 = new JPanel(new BorderLayout()); jPanel_1.setBorder(BorderFactory