layout-manager

How to arrange multiple panels in JFrame

瘦欲@ 提交于 2019-12-05 22:59:12
问题 I am trying to make a simple calculator to practice Graphics (i am a complete GUI noob). I am having some problems with having unneeded spaces after Polyashenkos Calulator and the text area and the space between the text area and the buttons. Also how do i keep that layout but eliminate the space and also make the bottom 3 buttons smaller. Any tips about what im doing or how i can do it better would be much appreciated. Thank you. import javax.swing.*; import java.awt.*; public class

how to set component size inside container with BoxLayout

吃可爱长大的小学妹 提交于 2019-12-05 22:43:11
问题 Faced with the problem of using BoxLayout In my example, I try to decrease the height of the text field and change the width of the buttons (as shown in green marker in the picture). I know about the techniques setPrefferedSize () and setMaximumSize (), but it did not work as it should. The line add(Box.createHorizontalGlue ()) also did not help. Thanks for any idea public class Testy extends JPanel { public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() {

How to set position of objects in JFrame?

匆匆过客 提交于 2019-12-05 22:27:32
I have Labels and JButtons i want to define the position in JFrame. import java.awt.*; import java.net.InetAddress; import java.net.UnknownHostException; import javax.swing.*; public class GuiFrame extends JFrame { public static void main(String[] args) throws UnknownHostException { JFrame f = new JFrame("This is a test"); f.setSize(400, 150); JRadioButton ButtonServer = new JRadioButton("Server"); JRadioButton ButtonClient = new JRadioButton("Client"); InetAddress thisIp = InetAddress.getLocalHost(); Label lip = new Label("Your IP is : " + thisIp.getHostAddress()); Label setup = new Label(

jpanel not displaying well with jframe set to gridbaglayout

淺唱寂寞╮ 提交于 2019-12-05 17:25:11
the program below is to position a jpanel at the top left conner of jframe with gridbaglayout but instead a very small box is displayed in center of jframe. when I set the layout of jframe to null, the jpanel displays fine. can someone tell me why the jpanel is compressed to the center of frame with gridbaglayout? i really need to use gridbag. please help import java.awt.*; import javax.swing.*; //swing package public class Major { //defining the constructor public Major() { JFrame maFrame = new JFrame("The main screen"); //creating main Jframe JPanel headPanel = new JPanel(); //creating the

JScrollPane does not appear when using it on a JPanel

旧城冷巷雨未停 提交于 2019-12-05 11:15:22
I have been trying for hours to find a way to solve the issue, but I had no luck with that. Here is a sample code: import java.awt.BorderLayout; import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.SwingUtilities; public class Example extends JFrame { private static final long serialVersionUID = 1L; public Example() { JPanel contentPane = (JPanel) getContentPane(); contentPane.setLayout(new BorderLayout()); JPanel panTop = new JPanel(new BorderLayout()); //JPanel panBottom = new JPanel

Swing BoxLayout problem with JComboBox without using setXXXSize

无人久伴 提交于 2019-12-05 10:48:07
here's an SSCCE: import java.awt.Color; import java.awt.Dimension; import javax.swing.Box; import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JPanel; public class BoxLayoutTest extends JFrame { public BoxLayoutTest(){ JPanel main = new JPanel(); main.setLayout(new BoxLayout(main, BoxLayout.Y_AXIS)); main.setBackground(Color.red); this.add(main); JPanel northPanel = new JPanel(); JPanel middle = new JPanel(); middle.setLayout(new BoxLayout(middle, BoxLayout.X_AXIS)); middle.add(new JButton("FOO")); middle.add(Box

The JPanel contentpane confusion

旧街凉风 提交于 2019-12-05 08:47:39
I am learning Java Swing and I appended a menuBar to the frame. By default this should call jframe.getContentPane().add(child) . When I ran the script the menuBar didn't show up. But the button was at the very top "y=0" if that makes sense. Then I realized my mistake I actually had to put in a menu in the menubar. Then the menuBar showed up. So that got me thinking...is the "menubar" "contentpane" actually 2 panels? It is confusing the hell out of me. Because that acted a lot like a panel. But getContentPane() returns a Container, not a JPanel object so I'm confused. If so, does that mean that

Understanding GridBagLayout constraints

会有一股神秘感。 提交于 2019-12-05 06:49:46
问题 I am relatively new to swing and I am trying to figure out exactly how it works. Tell me if I am wrong. I have mostly figured out gridx and gridy which is necessary to place a component. You need at least n values of (gridx,gridy) to create an nxn grid. For example (5,5),(3,3),(4,9),(3,10) will create a 3x4 gridspace(4 rows, 3 columns) with the components using the above (gridx,gridy) respectively placed in cells (3,2),(1,2),(2,3),(1,4). weightx and weighty seems to have 2 functions, a >0

Are there Constraint Layout Managers on iPhone OS?

删除回忆录丶 提交于 2019-12-05 04:46:14
The CA Programming Guide is talking about Constraints Layout Managers. However, the CALayer in the iPhone SDK doesn't have any constraints property or addConstraint method. They say iPhone OS just doesnt provide custom layout managers. But how about the standard ones? Unfortunately, despite the documentation saying so, even the springs-and-struts layout of layers is missing from the iPhone implementation of CALayer. This can be seen by the missing autoresizingMask property on CALayer on the iPhone. For Core Plot , we implemented our own custom layer layout via the -layoutSublayers method of

Make RecyclerView to wrap its content when using CardView with square ImageView

北城以北 提交于 2019-12-04 19:17:00
I am trying to achieve following structure (image below). As you can see there are two sections with RecyclerView s and CardView s in it. These two sections are divided by two TextView s with Button s. Each section should match screen width (minus indent between cards). Each CardView has square ImageView in it. So the height of CardView itself depend on screen width: card_height = screen_width - indent_between_cards + space_for_card_text . To achieve this behaviour I use simple SquareImageView , which looks like this: public class SquaredImageView extends ImageView { public SquaredImageView