layout-manager

Which java swing layout should I use

让人想犯罪 __ 提交于 2019-12-10 11:29:43
问题 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. 回答1: 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

My way to get X and Y index of buttons inside GridLayout

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-10 10:16:07
问题 This is related to How to get X and Y index of element inside GridLayout? post and its answers. For whatever reason none of them suggested to extend JButton to include its position in the grid and in associated array of buttons. I have made the following illustration that simply displays button's coordinates when it's clicked. Extended JButton : package buttons_array; import javax.swing.*; @SuppressWarnings("serial") public class ButtonWithCoordinates extends JButton { int coordX; int coordY;

Make RecyclerView to wrap its content when using CardView with square ImageView

余生颓废 提交于 2019-12-09 23:39:22
问题 I am trying to achieve following structure (image below). As you can see there are two sections with RecyclerView s and CardView s in it. These two sections are divided by two TextView s with Button s. Each section should match screen width (minus indent between cards). Each CardView has square ImageView in it. So the height of CardView itself depend on screen width: card_height = screen_width - indent_between_cards + space_for_card_text . To achieve this behaviour I use simple

Java Vertical Layout?

*爱你&永不变心* 提交于 2019-12-08 14:46:50
问题 I need to position a JLabel over some JButtons, vertically, like a game menu. They should all be centered. I already downloaded MigLayout, but I'm not sure how to use that, so I just want a way to position my components vertically and centered, MigLayout or not. Also, I don't want to use a IDE GUI designer. 回答1: You might use a (single column) GridLayout or BoxLayout for this. See Using Layout Managers & A Visual Guide to Layout Managers for more tips, ideas and working source. 回答2: You

Java Swing JList, can't set minimum width

徘徊边缘 提交于 2019-12-08 14:24:11
问题 Trying to simple create a JList with a specified visible row count, but a minimum width. It seems "setMinimumSize()" does nothing though... import java.awt.*; import java.awt.event.*; import javax.swing.*; public class UserInterface { final static private int HEIGHT = 400; final static private int WIDTH = 650; public static void main(String[] args) { JPanel content = new JPanel(); String[] entries = { "Entry 1", "Entry 2", "Entry 3", "Entry 4", "Entry 5", "Entry 6" }; DefaultListModel

How to add ChartPanel in JPanel inside a JFrame

一曲冷凌霜 提交于 2019-12-08 13:11:48
问题 I have been trying to do this.. JFreeChart chart = createChart(createDataset()); jPanel1 = new ChartPanel(chart, false); this JPanel1 is inside a JFrame ( its a JFrame Form of Netbeans, so i have some labels and textAreas) jPanel1 is fixed inside designer of Netbeans .. at some place after doing other work of data now i want a chart of my data under all the text about data.. I tried other solutions like casting the JFreeChart to jPanel. also JFreeChart chart = createChart(createDataset());

Java making Connect Four game panel

半城伤御伤魂 提交于 2019-12-08 09:34:59
问题 I'm making Connect Four for computer science class as my CPT. SO far I've created the panels but I am having an issue. What I am trying to do is make one panel per slot on the board and fill it with a picture of an empty slot of a connect four board, and when every spot is combined, it'll look like a complete connect four board. Basically I'm adding a grid layout panel to my main panel and filling the grid panel with multiple other panels containing the the slot picture. I've created a sub

MigLayout column constraint

◇◆丶佛笑我妖孽 提交于 2019-12-08 08:08:23
问题 I'm trying to develop an application layout like that: * +------------------+--------+ * | | | * | | | * | | | * | 70% | 30% | * | | | * | | | * | | | * | | | * | | | * +------------------+--------+ To do this, I'm using MigLayout. According to this cheat sheet, to set the column weight we shold use [weight] . However, it isn't working somehow. Take a look at my code: package com.test; import java.awt.EventQueue; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel;

Adding panel in center of container

我只是一个虾纸丫 提交于 2019-12-08 00:25:23
问题 I have a JPanel which is a BorderLayout and I have set a new panel in the top and container ( JDesktopPane ) in center and another panel in bottom. Now I want to set panel (card layout) dynamically in center of container as I am showing hierarchy below top --> panel panel(BorderLayout)center --> container(JDesktopPane) --> panel(CardLayout) bottom --> panel Here card layout contain different panel as card. problem is that I'm unable to show each card in center of container. 回答1: how to show

Absolute positioning (No layout manager) vs. absolute positioning in MiGlayout

萝らか妹 提交于 2019-12-07 20:06:44
问题 Will the final application result be identical across different platforms and resolutions etc. when using absolute positioning in MiGlayout as the layout manager compared to using no layout manager (Setting layout manager to null)? Is there a difference between the absolute positioning in MiGlayout solution vs. the no layout manager solution? 回答1: Think about this. Even if you supply a singe font for your application, it will be rendered differently on different OSs, it can even be rendered