null-layout-manager

Flashing JTextField and JButton

徘徊边缘 提交于 2019-12-13 05:13:44
问题 //ADDING BET FIELDS setLayout(null); horseChoice = new JTextField(); horseChoice.setBounds(200, 585, 300, 20); add(horseChoice); setLayout(null); horseBet = new JTextField(); horseBet.setBounds(200, 625, 300, 20); add(horseBet); //ADDING BET BUTTON setLayout(null); bet = new JButton("Place Bet"); bet.setBounds(250, 675, 200, 50); add(bet); I am trying to create two textfields where the users can type in what they want and a button to save their input to a variable. But when I run my program,

Java Swing Add JPanel to JPanel

梦想与她 提交于 2019-12-12 20:25:25
问题 The Situation I am currently trying to build a 2D game with Java's Swing. For this, I have my main class Puzzle which is subclassing JFrame . To my frame I add my main JPanel which consists of several JPanel s added together (each of them being a new piece). EDIT 2: PlayingField is my model which will store the current location of each piece. One can select a piece with the mouse (the plan is to highlight it) and move it with the arrow keys as long as the next step (a full cell, so approx.

Use a absolute layout inside a JScrollPane

安稳与你 提交于 2019-12-12 11:16:49
问题 I need to use a JScrollPane with absolute layoute. I know that the use of setLayout(null) is not recommendable at all. I've been reading that if you want to use the absolute layout with a JScrollPane it is necessary to set the preferred size property of the elements inside in order to JScrollPane can calculate its size. I've been trying the next code changing the order and sizes of elemnts but I can't work out where I've been wrong. import java.awt.Color; import java.awt.Dimension; import

How does JButton control it's size?

余生长醉 提交于 2019-12-11 12:43:43
问题 I have added a button to a frame and controlling it's text and/or minimum size with timer. I noticed, that button does grow sometimes, and sometimes does not. If in null layout, then it ignores both text and minimum width changing. If in FlowLayout layout, then it grows if text changing, but ignores minimum width changing. How make it grow in latter case? If minimum width changes, then why doesn't layout manager reshapes button? How to force it to reshape? Note: code below is SSCCE, i.e. it

JLayeredPane, background image + “icon” layer

╄→尐↘猪︶ㄣ 提交于 2019-12-11 08:37:17
问题 I need 2 separate JPanels (or any lightweight components) on top of each-other and ultimately embedded within a JPanel, either directly or through something like a JLayeredPane. Thus, no heavy-weight components or glass pane. The lower JPanel (named BackgroundPanel) paints a background image or plays a video while maintaining aspect ratio and using an alpha. The upper panel (called CompassPanel) has icons on it and allows the user to add icons, delete them, and move them around (like a

Center panel when window resized

你。 提交于 2019-12-11 07:50:12
问题 I would like to keep a panel I have created using an absolute layout in the center of my window even when the window is resized (if possible). I've come across a couple of suggestions here and [here][2] but no dice! Below is my sample code, any ideas or suggestions? I have no problems centered a single component like a JLable but I want to center a panel with many components! import java.awt.Color; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import javax.swing.JFrame;

Drawing a JComponent inside a JPanel

梦想与她 提交于 2019-12-06 14:10:23
I am trying to display a JComponent inside a JPanel. I am using null layout because location of the components can be changed during runtime and I have to control them. But the following code does not work. The JComponent only becomes visible on display if I explicity call the "paintComponent" method, which I think is not good practice. My JComponent Class public class MyIcon extends JComponent { private double xPos; private double yPos; private double radius = 30; public MyIcon(double xPos, double yPos) { this.xPos = xPos; this.yPos = yPos; this.setBounds((int)xPos, (int)yPos, (int)radius,

Java GUI button's label can't be seen

℡╲_俬逩灬. 提交于 2019-12-04 04:00:59
问题 I'm a second year student and I'm working on my OOP project (Calculator). I'm done with the functions of the numeric buttons and operators. Now I'm in the stage of re-arranging my buttons. At first, I just set my button size to (50,50), it works fine and its label is still visible, but when I decided to make it smaller (30, 30), its label turned into "..." instead. Here's the pic: And heres my code: lblEdit.setBounds(-138,-5,180,50); lblView.setBounds(-90,-5,180,50); lblHelp.setBounds(-40,-5

Adding JScrollPane to a JPanel without a Layout Manager

泪湿孤枕 提交于 2019-12-02 09:21:09
问题 Before I start, I'm aware that its a bad idea to not use a Layout Manager and usually I do use one, however, I also have all my components automatically re-size and relocate based on the size of the window. In addition the program I'm working on is only intended to run on 1 machine throughout its entire lifetime. Please don't downvote me just because of lack of layout manager, I found it to be what I need for this particular program. To my issue, I found a similar post on stackoverflow but a

Java GUI button's label can't be seen

江枫思渺然 提交于 2019-12-01 22:14:28
I'm a second year student and I'm working on my OOP project (Calculator). I'm done with the functions of the numeric buttons and operators. Now I'm in the stage of re-arranging my buttons. At first, I just set my button size to (50,50), it works fine and its label is still visible, but when I decided to make it smaller (30, 30), its label turned into "..." instead. Here's the pic: And heres my code: lblEdit.setBounds(-138,-5,180,50); lblView.setBounds(-90,-5,180,50); lblHelp.setBounds(-40,-5,180,50); txt.setBounds(15,35,250,30); // text pane txt2.setBounds(0,330,100,20); blank.setBounds(15,80