null-layout-manager

suitable LayoutManager for resizable components

对着背影说爱祢 提交于 2020-02-15 07:21:06
问题 sometime ago I read this article that shows a way to implement mouse resizable components in Swing. The author uses a null LayoutManager in order to allow absolute component positioning. I know that a null layout should never be used, so my question is: is there any already implemented LayoutManager that allow component's absolute positioning, or I have to implement it my own? 回答1: A layout manager really does 3 things: Set the location of a component. Since you need the ability to drag the

how to create layout in swing which does not change with frame size

£可爱£侵袭症+ 提交于 2020-01-17 02:21:10
问题 In my program the 2 panels log and Img are layouts which are not constant they keep changing i want to create a layout where all buttons and textview reamins constant irrespective of the size of frame. can anyone help me? here is my code import java.awt.CardLayout; import java.awt.Color; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.*; import java.awt.*; import java.awt.event.*; import javax.swing.JButton; import javax.swing.JFrame; import javax

JScrollBar Doesn't Do Anything

。_饼干妹妹 提交于 2020-01-05 07:08:17
问题 I'm trying to put a vertical JScrollBar on top of a JPanel. I can add the scoll bar easily enough, but when I run the program, my scroll bar doesn't have any effect. I can drag it up and down, but the contents of the JPanel don't move. I've read all what I can find about how to do this, and it seems very straightforward, but I'm obviously missing something. Please note that my JPanel layout is set to NULL. Here is the relevant code. Thanks! public JDlgResults(ArrayList<AnsweredProblem>

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

Alternative solution to null layout manager when absolute positioning is needed

不羁岁月 提交于 2019-12-31 01:44:12
问题 Few months ago i read this Swing tutorial http://zetcode.com/tutorials/javaswingtutorial/resizablecomponent/ for understanding how implementing resizable components inside Swing. The tutorial tells about using a null LayoutManager in order to have the possibility of absolute positioning child components. In a discussion relative to another subject @Andrew Thompson pointed out that using null layout is a bad idea. This article http://download.oracle.com/javase/tutorial/uiswing/layout/none.html

How to add scrollbar in JFrame with null layout?

北城以北 提交于 2019-12-25 01:46:44
问题 I want to add a vertical scroll-bar on my JFrame with null layout. Is it possible or not? please help! 回答1: Just set the JScrollPane as ContentPane for JFrame as it is described here: public class TabbedPaneTest { public static void main(String [] a) { final JFrame frame = new JFrame(); frame.setSize(500, 500); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JScrollPane pane = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); frame

Drawing a JComponent inside a JPanel

梦想的初衷 提交于 2019-12-22 20:46:50
问题 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,

Drawing a JComponent inside a JPanel

不羁的心 提交于 2019-12-22 20:46:12
问题 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,

ImageIcon by JLabel example with absolute positioning

寵の児 提交于 2019-12-14 00:06:09
问题 I have seen a lot of example code but none that specifically shows me how to display an ImageIcon through the use of a JLabel on a JFrame without using a layout manager. I am repeatedly told that absolute positioning is a hassle and less efficient than a layout manager but I'd prefer complete control over where my elements are going. A full scale example class (with no extra things added) of a JLabel that will display an image on a JFrame with absolute positioning would be much appreciated ,

JButtons don't load on panel until hovered over?

旧街凉风 提交于 2019-12-13 06:49:59
问题 When this is put on a frame, the buttons don't load until they are hovered over with the mouse, and then they stay up like they should. Here's the code: I've calling things like repaint() and revalidate() but none of them seem to have fixed the problem. The main and the Frame are seperate classes from the StartPanel. Thanks! JButton[][] levels = new JButton[3][8]; public StartPanel(){ setSize(1600, 1000); setLayout(null); int count = 1; int yValue = 150; for(int r = 0; r < 3; r++){ for(int c