setbounds

Have Winform appear on all existing monitors at same time (Its an alert window) [duplicate]

亡梦爱人 提交于 2019-12-13 02:27:10
问题 This question already has an answer here : Have winforms MessageBox appear on all screens, or specify Main or Secondary etc. (1 answer) Closed 5 years ago . I have a small application which functions as an alert system, I am using a form as the alert which appears on the screen, as they are more versatile and message boxes. Due to the nature of the alert, I need it to appear in the centre of all currently connected monitors.I have it appearing on hte main monitor only as of right now. I've

Why null layout and absolute positions are bad practice in Java Swing?

放肆的年华 提交于 2019-12-11 00:33:49
问题 I have code with null panel: JPanel thePanel = new JPanel(); thePanel.setLayout(null); and I used setBounds(x, y, width, heigth), f.e here: label2.setBounds(150, 220, 459, 311); I read that this is not a good practice, can you tell me why? Is it only because when you want to add something between one component and another you have to set them positions again and again or is it something else? I'd be very grateful for answer, thanks! ;) 回答1: There are multiple problems with absolute

How to dynamically add JLabels to JPanel?

跟風遠走 提交于 2019-11-28 01:56:32
I'm having a problem with this. I have a JPanel and normally I would create a JLabel like this: JLabel lblNewLabel = new JLabel("New label"); lblNewLabel.setBounds(0, 0, 135, 14); panel.add(lblNewLabel); but I want each time I click a button, in that panel to be created a new JLabel with the same size, but with a different height possition. I tried: panel.add(new JLabel(stringName)); but this way I don't get to set it's bounds. stringName I get from a JTextField. First off, use a layout . Done correctly the layout will place the components like you want. Secondly, when dynamically adding a

What is setBounds and how do I use it?

两盒软妹~` 提交于 2019-11-27 18:10:49
I cannot find anything on setBounds, what it is for, or what its function actually is. Could someone clear me up on this? Thanks so much! You can use setBounds(x, y, width, height) to specify the position and size of a GUI component if you set the layout to null . Then (x, y) is the coordinate of the upper-left corner of that component. setBounds is used to define the bounding rectangle of a component. This includes it's position and size. The is used in a number of places within the framework. It is used by the layout manager's to define the position and size of a component within it's parent

How to dynamically add JLabels to JPanel?

落爺英雄遲暮 提交于 2019-11-27 04:51:30
问题 I'm having a problem with this. I have a JPanel and normally I would create a JLabel like this: JLabel lblNewLabel = new JLabel("New label"); lblNewLabel.setBounds(0, 0, 135, 14); panel.add(lblNewLabel); but I want each time I click a button, in that panel to be created a new JLabel with the same size, but with a different height possition. I tried: panel.add(new JLabel(stringName)); but this way I don't get to set it's bounds. stringName I get from a JTextField. 回答1: First off, use a layout.

What is setBounds and how do I use it?

荒凉一梦 提交于 2019-11-26 15:38:14
问题 I cannot find anything on setBounds, what it is for, or what its function actually is. Could someone clear me up on this? Thanks so much! 回答1: You can use setBounds(x, y, width, height) to specify the position and size of a GUI component if you set the layout to null . Then (x, y) is the coordinate of the upper-left corner of that component. 回答2: setBounds is used to define the bounding rectangle of a component. This includes it's position and size. The is used in a number of places within

Showing a Windows form on a secondary monitor?

送分小仙女□ 提交于 2019-11-26 03:38:31
问题 I\'m trying to set a Windows Form on secondary monitor, as follows: private void button1_Click(object sender, EventArgs e) { MatrixView n = new MatrixView(); Screen[] screens = Screen.AllScreens; setFormLocation(n, screens[1]); n.Show(); } private void setFormLocation(Form form, Screen screen) { // first method Rectangle bounds = screen.Bounds; form.SetBounds(bounds.X, bounds.Y, bounds.Width, bounds.Height); // second method //Point location = screen.Bounds.Location; //Size size = screen