absolutelayout

Java swing, scrollbar does not working with absolute layout

本小妞迷上赌 提交于 2019-11-27 08:47:48
问题 I want to have a jpanel with fixed size without layout manager in jscrollpane (which will be also without layout manager). I cant use any layout manager because i need to create an rectangle/circle at a location where user clicks (and allow drag & drop for all the created emelents) setLocationRelativeTo(null); setSize(300,300); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setName("dnd test"); int v=ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED; int h=ScrollPaneConstants.HORIZONTAL

Changing position of a button

余生长醉 提交于 2019-11-26 17:14:08
问题 I have one button in an AbsoluteLayout in an XML file. From there I am able to set the (x,y) position of the button. How can I get and set the (x,y) coordinates of the button programmatically? Thanks all. 回答1: You have to get a reference to you button, for example by calling findViewById(). When you got the reference to the button you can set the x and y value with button.setX() and button.setY(). .... Button myButton = (Button) findViewById(R.id.<id of the button in the layout xml file>);

Android: Change absolute position of a view programmatically

♀尐吖头ヾ 提交于 2019-11-26 16:43:30
问题 If you use an AbsoluteLayout (I know that it is deprecated, but it was the only way to solve my problem) you can give the childViews the tag android:layout_x and android:layout_y to set their absolute position within the AbsoluteLayout . However I don't want to set these information in the xml, because I only know them at runtime. So how can I set these parameters at runtime programmatically? I don't see any method on the View like view.setLayoutX(int x) or something. Here is my XML, which