layout-manager

Automatically re-sizing a component within a GridBagLayout

风流意气都作罢 提交于 2019-12-12 10:58:02
问题 In this code I have a panel in the GridBagLayout which contains a JLabel and a JTextField . import java.awt.*; import javax.swing.*; public class Simple { JFrame simpleWindow = new JFrame("Simple MCVE"); JPanel simplePanel = new JPanel(); JLabel lblSimple; JTextField txtSimple; public void numberConvertGUI() { simpleWindow.setBounds(10, 10, 420, 80); simpleWindow.setMinimumSize(new Dimension(420, 80)); simpleWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); simpleWindow.setLayout(new

Is there any way to force GridLayout to leave empty cells?

一曲冷凌霜 提交于 2019-12-12 08:34:02
问题 I have a JTabbedPane with 2 JPanels set to GridLayout(13, 11). The first JPanel has enough of the cells filled out that it leaves the empty cells. The second JPanel has significantly fewer cells filled and this results in each button getting stretched to fill an entire row. Is there any way to get GridLayout to honor the empty cells, so the buttons in both JPanels are the same size? 回答1: Use nested layouts to get your desired result. Some layouts respect the preferred size of components and

How to set the location of a button anywhere in your JFrame

╄→尐↘猪︶ㄣ 提交于 2019-12-12 08:16:53
问题 What I want to do is put the button down the bottom left of the application. Could somebody just give me an example of how to do it? This is what I have: Here's my code: super("Test"); /**Create Components**/ JPanel addPanel = new JPanel(); JButton addButton= new JButton("Add"); /**Add Components**/ addPanel.add(addButton); this.add(addPanel); /**Set Components Properties**/ addButton.setLocation(12, 371); addButton.setPreferredSize(new Dimension(116, 40)); addPanel.setLocation(12, 371);

Resizing JTextField in JMenuBar

时间秒杀一切 提交于 2019-12-12 05:37:13
问题 I'm trying to add a JTextField as a search bar to a JMenuBar at the top of my JFrame . My problem is that the JTextField keeps getting resized to take up all available space in the JMenuBar , and I don't want it to. I've tried setPreferredSize() and setMaximum Size() , but these didnt work, presumably because the LayoutManager used in the JMenuBar doesn't respect these sizes. I also tried adding the JTextField to a JPanel with a FlowLayout and adding the panel to the JMenuBar , but I get

Bottom-to-top layout in Java with dynamic sizing

烈酒焚心 提交于 2019-12-12 05:27:45
问题 I am trying to build a common chat interface with chat-"bubbles" that fills up from the bottom. I am new to Java and can't figure out which Layout Manager to use. I have tried using the BoxLayout and some Glue at the top to push down the inner JPanels, but that forces me to set a "setMaximumSize" on them, which prevents the resizing based on the text inside the "bubbles". You can see the expected result above. Each bubble-row is a JPanel. They are all aligned bottom. The bubbles should be

Fit all components from JFrame to actual size of window

佐手、 提交于 2019-12-12 05:08:23
问题 I'm using NetBeans. How I can make all components from my window to resize to actual size of the window? Now when my window is 800x600 and I make it larger, size of all components are the same. I would like to change size of my components when I change size of open application window. I tried to search for answer on the internet but I couldn't find good answer to my problem. 回答1: I tried to search for answer on the internet but I couldn't find good answer to my problem. I find that hard to

Why does my StaggeredGrid RecyclerView layout every item, not only visible ones?

寵の児 提交于 2019-12-12 05:06:51
问题 I have a Staggered grid containing 370 items, with images. I want to make sure the items are recycled quickly to be careful with memory, but a ViewHolder is created and then bound for every single item in my adapter and pays no attention to whether children are visible I've tried the following StaggeredGridLayoutManager lm = new StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.VERTICAL); rv.setLayoutManager(lm); rv.setItemViewCacheSize(20); //Has no effect RecyclerView

Setting JLabels in rows and placing the equivalent JTextField right next to it

一世执手 提交于 2019-12-12 04:24:22
问题 I am trying to create 4 JLabel components 4 JTextfield components for my Swing based application. I am adding these lables and text fields in one of the many panels of the application. The class for this panel is as follows: public class CustomerInfoPanel extends JPanel implements ActionListener { private Car[] carList; private CarSalesSystem carSystem; private int currentIndex = 0; private JLabel headingLabel = new JLabel("Enter your details and let us find a car for you"); private JLabel

GridBagLayout Formatting

一曲冷凌霜 提交于 2019-12-12 03:59:59
问题 Solved using box layout in the panels that have 1 column and many rows. 回答1: I suggest you use a Table instead of working with single labels and GridBagLayout. It might be possible to use Colspan, too, see: Jtable Row Span and Column Span If its just a View (No Buttons, etc.), you could also consider to use a JEditorPane and render your View with HTML, that might be the easiest way. 来源: https://stackoverflow.com/questions/32973167/gridbaglayout-formatting

Java change JTextField size inside a GridLayout

五迷三道 提交于 2019-12-12 03:18:29
问题 I have a GridLayout(3,2) as follows with 2 JLabels, 2 JTextFields and a JButton. I add them as shown in the pic or code. Everything is just fine but the JTextField size is too big and I want it to be as shown by the red lines I've drawed. I have tried saying jtf3.setPreferredSize( new Dimension( x, y ) ); but it didn't change the dimension at all. One other solution was to make the GridLayout somewhat GridLayout(3,2,1,50) for example (by adding 50) but that moves the JLabels way top too... I