layout-manager

JLabel in GridLayout

浪尽此生 提交于 2020-01-04 03:00:34
问题 How to add JLabel out of the GridLayout ? I have an 8x8 grid layout. Container content = getContentPane(); content.setLayout(new GridLayout(8, 8,2,2)); for (int f = 0; f < btnArr.length; f++){ for (int s = 0; s < btnArr.length; s++){ btnArr[f][s] = new JButton(); btnArr[f][s].addActionListener(this); content.add(btnArr[f][s]); btnArr[f][s].setBackground(randomColor()); } } 回答1: import java.awt.*; import javax.swing.*; class SimpleNestedLayout { public static void main(String[] args) {

Two JPanels in JFrame , One under other

依然范特西╮ 提交于 2020-01-03 18:59:53
问题 I've got two panels in my frame, and I would like to set them one under other, and this first should have size like 9/10*screen frame, and this second 1/10. I've tried with GridLayout (2 rows and one column) but I can't set them specific size. How should I do that? ok maybe I will write some my code: I am writing game - pacman, and in the first panel there is a whole game, and in this second I would like to display player info(like score, name etc.) This first I would like to set on 80%

Swing vertical Navigation Menu

邮差的信 提交于 2020-01-03 05:57:07
问题 I am creating desktop application and design using Swing. i have two panels in frame left and right panel, In the left panel I have buttons, So i want that when i click on button from left panel it should display the result in right panel on same frame. Does i need to create another frame with same left panel and create a right panel for the link , or there is a way for above written method have no idea that how to do this. Like Shown in below Image. 回答1: I'd lay it out like this (there are

Setting an arbitrary width in GridBagLayout

青春壹個敷衍的年華 提交于 2020-01-03 05:16:10
问题 I was trying to make a keyboard layout, where one can specify the buttons' width. Therefore, I made an attempt with GridBagLayout but without success. To illustrate my problem I did a simple example, where I expected to obtain this (Button2, Button4, Button5, Button6): but instead I get Button4 and Button6 of double width. The code is: package views; import java.awt.BorderLayout; import java.awt.EventQueue; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import javax.swing

How to layout? (JFrame, JPanel, etc.)

折月煮酒 提交于 2020-01-03 03:06:11
问题 I'm very new to Java Swing and Java overall (my class just got finished on Scanner and basics). I was taught only Swing basics which is "What is a JFrame..etc" and I'm stuck on how to layout or position things. On the image is the layout I desired and could anyone help and teach me how to code it? JFrame with, 5 JPanel components?(4 columns and the order form below) Additionally, when clicking the "CONFIRM" button, I would want a new window to popup. How would I be able to link multiple

How to set LayoutManager for RecyclerView in Android

人走茶凉 提交于 2020-01-02 08:11:46
问题 In my application I want show some RecyclerViews . I want show 3 item in one row , I my application should use 4 recyclerView because each recyclerVews each data other API . In one of RecyclerView I can show 3 Item in one row, and I should show another 3 recyclerViews above of this RecyclerView . Please see this image to understand my mean : I write below code in Java : if (movieResponse.getData().getStars().size() > 0) { starsModel.clear(); starsModel.addAll(movieResponse.getData().getStars(

How to set LayoutManager for RecyclerView in Android

家住魔仙堡 提交于 2020-01-02 08:11:31
问题 In my application I want show some RecyclerViews . I want show 3 item in one row , I my application should use 4 recyclerView because each recyclerVews each data other API . In one of RecyclerView I can show 3 Item in one row, and I should show another 3 recyclerViews above of this RecyclerView . Please see this image to understand my mean : I write below code in Java : if (movieResponse.getData().getStars().size() > 0) { starsModel.clear(); starsModel.addAll(movieResponse.getData().getStars(

How to align JLabel to the left of the JPanel?

牧云@^-^@ 提交于 2020-01-01 04:48:11
问题 I want to align my JLabel to the left. String lText = "<html><b><font color = white face = comic sans ms size = 20>mybook</font></b></html>"; JLabel label = new JLabel(lText); label.setBorder(new EmptyBorder(25,0,25,500)); I tried to do it using EmptyBorder but it isnt aligning properly. I am using FlowLayout 回答1: FlowLayout uses CENTER alignment by default. Try using LEFT alignment for your JLabel JPanel container myJPanel.setLayout(new FlowLayout(FlowLayout.LEFT)); 回答2: You might wish to

JScrollPane not working in null layout

走远了吗. 提交于 2019-12-31 05:37:06
问题 import javax.swing.JCheckBox; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollPane; public class ScrollJPanelDemo extends JFrame { public ScrollJPanelDemo(){ setSize(480, 200); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JLabel label = new JLabel("Select one or more options : "); JCheckBox jcb1 = new JCheckBox("Chandigarh"); JCheckBox jcb2 = new JCheckBox("Mohali"); JCheckBox jcb3 = new JCheckBox("Delhi"); JCheckBox jcb4 = new

Using CardLayout for multiple JPanels and nothing displays

心已入冬 提交于 2019-12-31 05:11:32
问题 I'm making a simple (and bogus) computer power consumption calculator. I'm using a card layout to put multiple panels in but when I run it, there's just a small window not displaying anything. Here's my long code, I put it all in one class. package my.Project; import java.awt.*; import java.awt.event.*; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import java.text.DecimalFormat; import javax.swing.*; public class MainProject extends JFrame { CardLayout