layout-manager

Elements not showing in GridBagLayout

六眼飞鱼酱① 提交于 2019-11-27 08:40:29
问题 I am using GridBagLayout as JFrame layout. My elements are not showing no matter what i write. Please don't give answers which use anything but GridBagLayout(sorry if it sound rude) JPanel Panel; JButton insertButton = new JButton("Insert"); GridBagConstraints gbc; public MainFrame() { this.setTitle("JAVA & MySQL"); this.setVisible(true); this.setBounds(500, 100, 600, 600); this.setDefaultCloseOperation(EXIT_ON_CLOSE); Panel = new JPanel(new GridBagLayout()); Panel.setOpaque(true); Panel

GridBagLayout cant get layout right

久未见 提交于 2019-11-27 08:20:05
问题 I'm new to GridBagLayout but I tried to use the standard convention that I could find which was to draw out my idea on a piece of grid paper and then try and translate the grid values into gridbag... my goal is to make the layout like you see below: it currently looks like this: any idea's as to why? the exact dimensions i'm looking for if you think of a grid with the upper left hand corner being 0,0 for the red in panel in the goal picture: start at column 0, span 10 columns, with height 1

Laying out a keyboard in Swing

扶醉桌前 提交于 2019-11-27 08:02:37
问题 I've been trying to reproduce this layout: Here I am: using: import javax.swing.*; import java.awt.*; public class Keyb { private JFrame f = new JFrame("Keyboard"); private JPanel keyboard = new JPanel(); private static final String[][] key = { {"`", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "-", "=", "Backspace"}, {"Tab", "Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", "[", "]", "\\"}, {"Caps", "A", "S", "D", "F", "G", "H", "J", "K", "L", ";", "'", "Enter"}, {"Shift", "Z", "X", "C"

How to make draggable components with ImageIcon

那年仲夏 提交于 2019-11-27 07:22:15
问题 I'm trying to build a user interface for a chess game. I've used a GridBagLayout filled with JLabels and the chess pieces are ImageIcons of the JLabels . Now I would like to move the pieces by dragging it on the board. Is there a way to do this with ImageIcons ? Or is there a better way to solve the problem? EDIT: here is a sample code. you can notice that you can move the iconImage, but it doesn't "drag" with the mouse. import java.awt.BorderLayout; import java.awt.Color; import java.awt

Automatically increasing font size in Swing

半城伤御伤魂 提交于 2019-11-27 07:16:00
问题 I would like to know if there are methods of automatically increasing the font size based on the size of a component. I have this gui here: Hovewer if i increase the size of the frame, it becomes like this: the font size doesn't increase. and i don't have an idea on how to make this work. 回答1: Some L&Fs support a sizeVariant, illustrated here with com.apple.laf.AquaLookAndFeel . Alternatively, you can scale the font to fill the space allocated by your chosen layout, as shown here. 来源: https:/

Clear components of JFrame and add new components

半世苍凉 提交于 2019-11-27 05:22:48
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.*; public class GuiFrame extends JFrame { final JFrame f = new JFrame("Test"); public void Starter(){

.setBounds not working for JLabel and JButton

左心房为你撑大大i 提交于 2019-11-27 04:55:07
问题 I am trying to change the positioning of a JLabel and a JButton on my GUI. Even though I try to use .setBounds to change their locations; they both just appear in the top centre of the screen. import java.awt.color.*; import java.awt.font.*; import java.awt.Graphics; import java.awt.Image; import javax.swing.*; import javax.swing.*; import java.awt.event.*; import java.awt.*; import javax.swing.UIManager.*; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; public class yo

Position on Screen Right Bottom

☆樱花仙子☆ 提交于 2019-11-27 04:46:24
问题 I need to position JFrame on my screen. But I can't make them appear on the right side of the screen bottom. Please can someone explain me how to position them, if you can describe how to do it, it would be great. Here is the code so far. //Gets the screen size and positions the frame left bottom of the screen GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice defaultScreen = ge.getDefaultScreenDevice(); Rectangle rect = defaultScreen

Position Image in any Screen Resolution

≯℡__Kan透↙ 提交于 2019-11-27 04:08:15
问题 I have a problem with my program. Every time when I change my screen resolution, my image starts to move out of position. Any suggestions on how to make my image stay in the same location even though I change to any other resolution? p2 = new JPanel(); p2.setLayout(new FlowLayout()); ImageIcon img2 = new ImageIcon("C:\\Drum\\Invisible4.png"); jbtn2 = new JLabel(img2); p2.add(jbtn2); add(jbtn2); jbtn2.setSize(jbtn2.getPreferredSize()); jbtn2.setLocation(140, 380); 回答1: I prefer to always try

What layout accepts percentages instead of values in swing?

淺唱寂寞╮ 提交于 2019-11-27 03:38:18
问题 I need to create frame content based on their percentage of visual space they need. For example 20% for panel1,80% for panel2. what layout does this kind of layout management? 回答1: in reduced form GridBagLayout , but with success for your requirement 80% - 20% import java.awt.*; import javax.swing.*; import javax.swing.border.*; public class BorderPanels extends JFrame { private static final long serialVersionUID = 1L; public BorderPanels() { setLayout(new GridBagLayout());// set