Size « Layout « Java Swing Q&A





1. Controling the size of components in Swing when their frame is resized    stackoverflow.com

I have a simple form like this: Username: .......... Password: .......... When the form is re-sized, I would expect JTextField (illustrated by .........) to be re-sized horizontally to fit the new width but not ...

2. Swing custon JComponent size    stackoverflow.com

I want to create a custom JComponent (specifically a custom JToggleButton) that has a custom appearance. What i want to do is simply override the default painting of the component and ...

3. Java AWT/Swing: Get notified on change of position/size of my window    stackoverflow.com

I've got a window and I would like to get notified when the position or the size has changed. Which type of listener ist the best to take? WindowListener didn't work for ...

4. How can I set a JPanel maximum or preferred size that uses gridLayout?    stackoverflow.com

I had problem using a very simple frame containing two JPanel. The problem is on the layout of the Center JPanel that contains four JButton. How can I set a better size ...

5. two panel in java (first panel has fix size, second has remainder size)    stackoverflow.com

I want some like this: http://eta.name/timages/JPanel_Layout.png (sorry, I have no reputation to post image) How make it ideologically correct?

6. Can Box Layout accept size of included elements?    stackoverflow.com

I used myPanel.setLayout(new BoxLayout(myPanel, BoxLayout.Y_AXIS)); to order panels vertically (one under another one). But myPanel defined in the shown way change the included panel. In more details, it tries to set ...

7. Minimizing and Restoring Swing Window Breaks Layout and Repaint    stackoverflow.com

I've written an application in Swing that listens for UDP packets from a smart battery and displays them in JTextFields inside a JPanel inside a JFrame. For some reason, minimizing ...

8. Jframe does not remember it' s position after minimizing    stackoverflow.com

Hi My problem is that , The Jframe window does not remember it's position after minimizing ....suppose I minimize at co'ordiates (45,89)..but after maximizing it again open at (37,28)..means at different co-ordinates ...

9. Getting correct sizing behaviour in a custom Swing component    stackoverflow.com

I'm creating a custom Swing component that inherits from JPanel. What is the right way to override/implement the various sizing methods (getPreferredSize, setPreferredSize, getMinimumSize etc.) in order to get "good behaviour", particularly ...





10. Is it possible to make GridLayout's components not equal in size?    stackoverflow.com

GirdLayout makes a bunch of components equal in size. That means that the biggest sized component will define the size for all components. Is it possible to make each component's size ...

11. Layouts and minimal sizes    stackoverflow.com

I'm trying to insert a new panel with a minimal size set onto an existing form. Unfortunately after I do this:

this.add(scrap);
this.moveScrapCentre(scrap); // runs setLocation(...)
this.revalidate();
this.repaint();
(where this: JPanel with null layout, scrap: JPanel ...

12. Java Swing; Problems with Java GraphicsConfiguration.getBounds() returning 0    stackoverflow.com

It seems that the .getBounds() method of the GraphicsConfiguration class is not reporting the correct values.

   GraphicsDevice[] gdArr = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();

        int width ...

13. Java Swing: How do I define one minimal dimension (of the two) for components?    stackoverflow.com

To define minimal size successfully, I have to do the following:

// setting minimal width AND height
Dimension min = new Dimension(100, 100);
comp.setMinimumSize(min);
comp.setPreferredSize(min);
comp.setSize(min);
When I left one line out it doesn't work, which is ...

14. Why is this JPanel not sticking to the specified size?    stackoverflow.com

So, I'm trying to learn Java Swing and custom components. I've created a JFrame, given it a background color, and added a JPanel:

    JFrame frame = new JFrame("Testing");
 ...

15. Java/AWT/Swing: about validation and sizes    stackoverflow.com

I'm a bit confused at how to manage the layout of my components in Java (I want to do it manually and not handle it by a layout manager). There are ...

16. How to set the component size with GridLayout? Is there a better way?    stackoverflow.com

I am working on a larger GUI with Java and I am becoming angry on Layout Managers. I have a "Settings-Panel" with a variable number of JComponents in it (Labels, Buttons, JSpinners, ...





17. How to make graphical objects be static during re-sizing?    stackoverflow.com

Below I have attached the code, that draws a simple vertical line at the centre of the window, but when I resize the window, the line leans towards the resizing direction. But ...

18. Java: Adding JComponents to a JPanel with static sizing and positioning    stackoverflow.com

I have a program that reads and draws an SVG file in a java application without the use of third party libraries. I have gotten to the point where I can ...

19. set size wont work in java    stackoverflow.com

public void start_Gui() {

        JFrame window = new JFrame("Client Program");
        window.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE);

      ...

20. Java Swing elements sizing and positioning issue    stackoverflow.com

I'm creating a Java swing app and I'm having a real hard time getting elements positioned nicely. How would I go about making the input boxes and combo boxes to say 30px ...

21. Opening a new jframe with the same properties as the closed one    stackoverflow.com

How can I have the newly open jframe have the same properties like Size and position on screen. Thanks

22. Java Swing getSize() returns inaccurate value?    stackoverflow.com

To put this most simply, I am trying to use the width of a component to set the size of its parent container. However the width being returned for the component ...

23. Can I get the right jComponent size before it's shown?    stackoverflow.com

When is the size of the jComponent is calculated? After being shown in the screen or before that? if I send .getSize() message before .setVisible(true), would it give me the right answer? Thanks ...

24. How can I properly center a JPanel ( FIXED SIZE ) inside a JFrame?    stackoverflow.com

Hi all! I'm trying to solve an -apparently- simple problem, but I cannot fix it. I'm working on a sample application with Java/Swing libraries; I have a JFrame and a JPanel. I just want ...

25. Should I avoid the use of set[Preferred|Maximum|Minimum]Size methods in Java Swing?    stackoverflow.com

I received several times a critic for having suggested the use of the following methods:

  1. setPreferredSize
  2. setMinimumSize
  3. setMaximumSize
on Swing components. I couldn't see any alternative to their use when I want to define proportions ...

26. How to adjust the size of a TableViewer inside a GridLayout    stackoverflow.com

I have a TableViewer inside a GridLayout. Everything works nice and the Table Viewer shows up as a white area with some data in it. The problem is that the white area ...

27. Java reuse Dimension objects when setting component size    stackoverflow.com

Is it contraindicated to use several presetted dimension objects to set the preferred size of non resizable components on the screen. E.g.: two textfields both should be 80x20 px so:

Dimension d = ...

28. Read JFrame size from JPanel    stackoverflow.com

I have a Layout class which extends JFrame. Later I am adding RoadPanel which extends JPanel. At run-time is it possible to know Layout frame size in RoadPanel? Code

class Layout extends JFrame{
 ...

29. QGraphicsView size in a GridLayout    stackoverflow.com

I have found this: Getting the size of a QGraphicsView But I can't figure out what does it mean to "move my initialization code to showEvent" and I can't comment on ...

30. Java PaintComponent size and position in a subclass of an abstract class that extends Jpanel    stackoverflow.com

I'm building a simple chess game and am stuck on trying to paint drawings on a Panel I have a board ready and on the board there are panels. those panels are ...

31. How do I set hard limit on a JComponent when setMaximumSize() and setPrefferedSize() don't work?    stackoverflow.com

I'm trying to make an image processing frame similar to one found in something like Photoshop or Paint Shop Pro and I'm running into problems. Right now I have a JFrame window ...

32. define container minimum size using java layouts    stackoverflow.com

i am writing a stand alone app in java using a couple of JPanel with different layouts in order to arrange the user interface. now my problem is that when i take ...

33. figuring out heap size for large swing app    forums.netbeans.org

I've built a swing application with NB and the swing app framework. It is fairly large and can get pretty memory hungry. I worry about the initial heap size being inadequate. ...

34. Decrease NB's GUI size    forums.netbeans.org

Hello, I'm using Netbeans 6.9 on Ubuntu 10.04 and the GUI (panels, buttons...) is so "big". Is there any possibility to decrease its size? I was using NB on Windows and ...

35. Set size and location Swing Frameview    forums.netbeans.org

I have an application that uses the Frameview for the main GUI window. I'm having difficulty setting the size and location from the setting the user saves. this.getFrame().setX = left this.getFrame().setY = top this.getFrame().width = width this.getFrame().height = height no matter what I do, the thing is in the center of the screen and ignores the values I set, although I ...

36. getBounds()/getWidth() returns 0    coderanch.com

I need to add a number of labels to a Panel. If the labels are more than can be accomodated on the Panel, then I need to display a label/button to allow the user to scroll. I do not want to use a ScrollBar. My call to getWidth() and getBounds() both is returning 0. Thus I have no way of knowing ...

37. How do I specify a component's exact size?    coderanch.com

Obviously the Swing class often controls the size of components. I want to be able to control the size at times as well. Is this possible? This would give me more control of look at feel rather than letting Swing fully take control. -Dale ------------------ What's this H2SO4 doing in my fridge?? ( thud )

38. table size under JDK1.2.2 vs. JDK1.3    coderanch.com

Hi, I have a simple table with 4 rows (JTable in ScriollPane). I set scrollpane's preferredsize to fit accurately (designed in JDeveloper JDK 1.2.x) and also table.setRowHeight() . when I run this small program under JDK 1.3 the table doesn't fit into the scrollpane, the difference is about 3 pixels. Running under JDK 1.2.2 is OK. No matter which one javac ...

39. Layout Managers and preferred size    coderanch.com

Hi. I am having a problem laying out a gui. I want to place five buttons and five labels on a panel. I want the button to have a corresponding label. I can do this with Grid Layout. However, I want the buttons to be small. Grid Layout will not let me set the size of the buttons. What would be ...

40. Problem with size    coderanch.com

Hi. I have an app that has fields that are setVisible(false) when my application runs. If the user clicks a certain button, these fields are supposed to appear. My problem is when they appear, they are tiny. I think it is becuase when the app ran, these fields were not visible, so it didn't pack them. I need to know how ...

41. JFrame position and size    coderanch.com

hi, if your layout management works fine, use pack() and let the components compute their preferred size (of course you should set the preferred size of tables, trees etc.). pack() should be called instead of setSize() (it will overrule setSize if called afterwards, or setSize will overrule pack() in the opposite case), after adding all components, and before calling setVisible(). if ...

42. How to set the size of aJList?    coderanch.com

43. Swing method to size component    coderanch.com

44. changing sizes in GridLayout    coderanch.com

45. JTextAera sizing issue ?    coderanch.com

What sort of layout are you using in the component that holds the text area? What you might want to do is set JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS so you can account for the size of the scrollbar when initially laying out your components. The side effect is that there will be a scrollbar in your text area even when you don't really need one, ...

46. JComponent Change Size?    coderanch.com

47. Minimum Size & GridBagLayout    coderanch.com

I'm using GridBagLayout in a complex form and I simply want to have each 'cell' be exactly the same width, when the size of the window changes the width of each cell scales accordingly, but each cell always remains the same size as the other. This way I can simply place items by specifying the location and number of cells it ...

48. Fixed Sizes and positions    coderanch.com

I'm a newbie to SWING programming so bear with me if these are simple questions... 1. Is it possible to ensure that a screen can't be resized? How can you do this? 2. How do you make sure that a textfield is not stays in the same position and has the same size even if the window is resized Regards

50. Sizing up all my components!    coderanch.com

well, for the JLabel anyhow, maybe extend it to create a JLabel that has the attributes you want and make all your JLabels one of those objects. (e.g., MyBlueTahomaLabel, MyBlueTahomaCheckBox, etc). or make a "label adder" helper method that (if called) will add the label in the desired font and color (e.g., addBlueTahomaLabel(String text, ...)). this works best if your layout ...

51. Implementing the Scrollable interface: viewport size    coderanch.com

I read the JavaDoc. These 2 methods only tell whether my JScrollablePanel's size should or should not depends on the viewport's size. That means, if I return true in these 2 methods, my JScrollablePanel's size will become dynamic and resize itself whenever the viewport that display it is resized. But the viewport's size is still not dynamic..... Am I right?

52. Setting a size    coderanch.com

53. Question about component sizes    coderanch.com

54. nested components and sizing    coderanch.com

i have a ui that is made up of nested components. the problem i have is that the size of the nested components depends on the font size which i think i get from Graphics passed into paintComponent. so, how do i work out the size of a component prior to painting it? it seems like i have to paint all ...

55. Fixed Size    coderanch.com

56. set.Size    coderanch.com

The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - ...

57. gridlayout - set size    coderanch.com

GridLayout doesn't pay much attention to the size of the components you hand it. It divides the available space up according to the number of rows or columns you specify and adds the components. I was unable to create the behavior you describe. If this app doesn't help maybe you can modify it to show the behavior. import java.awt.*; import java.awt.event.*; ...

58. GUI sizing    coderanch.com

59. Java Page Size    coderanch.com

Just for some clarification..It sounds like you have told your application what size to print the page, and are asking how to tell the printer to print it at that size? Err... is that what the class is supposed to do? I don't understand your question completely, and the API is a bit unclear to me. [ December 03, 2005: Message ...

60. size of the Component    coderanch.com

61. Minimizing and Maximizing    coderanch.com

Hi All, Ok what i would like to do is to create a main window which has place holders for variouse componants that i will be adding later. now i dont like the default close maximize and minimize buttons on an application so i got rid of them. but i still want to use the functions so i created another panel ...

62. Component size    coderanch.com

63. size    coderanch.com

here's your 'knob only'. Don't know your definition of small, perhaps if you advise the range of the slider and size relative to what I post, it might give us a better idea. import java.awt.*; import javax.swing.*; class Testing extends JFrame { public Testing() { setDefaultCloseOperation(EXIT_ON_CLOSE); setLocation(300,200); SliderKnobOnly sko = new SliderKnobOnly(0,50,0); sko.setPreferredSize(new Dimension(25,20)); getContentPane().add(sko); pack(); } class SliderKnobOnly extends JSlider ...

65. component size    coderanch.com

When it's NORTH or SOUTH, it gets its preferred height, but not its preferred width. When it's EAST or WEST, it gets its preferred width, but not its preferred height. As advertised: see the BorderLayout class api, specifically the paragraph in the comments section that appears just above the demo app image. The technique for getting these outer sections of BorderLayout ...

66. JTextaArea - Lock the size, can it be done?    coderanch.com

in this you would need to control the size of the textArea e.g. frame.setResizable(false); compile/run, start typing and it will be limited to 2 lines. if you then narrow the frame, the typed text will go to 3 or more lines import javax.swing.*; import java.awt.*; import javax.swing.text.*; class Testing { JTextArea ta = new JTextArea(); final int MAX_LINES = 2; int ...

67. gui component sizes    coderanch.com

Hi all, In building a GUI there are various methods for setting the sizes of components. For instance setSize, setPreferredSize, setMaximumSize, setMinimumSize and what I was wondering is which components is one meant to set the sizes for and which methods does one use and when. For instance if I have a frame that contains a panel (that is as big ...

68. Components size    coderanch.com

This is an executable SSCEE code. import java.io.*; import java.util.List; import java.util.ArrayList; import java.util.LinkedList; import java.util.ListIterator; import java.awt.Font; import java.awt.Color; import java.awt.geom.GeneralPath; import java.awt.geom.*; import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.event.ActionEvent; import java.awt.Event; import java.awt.*; import java.awt.BorderLayout; import javax.swing.*; import java.util.Hashtable; import javax.swing.event.*; import java.applet.Applet; public class Height extends JApplet{ private BasicGraphicPanel graphicPanel; private JPanel jPanel1; private JSlider dJSlider; private ...

69. Monitor Size    coderanch.com

What do you think is wrong with it? I've just run it and seem to get realistic output. I assume you're not expecting an exact answer like 15 inches - a 15 inch monitor will have an actual screen size of slightly less. [Edit: punctuation] [ February 07, 2008: Message edited by: David Payne ]

70. size    coderanch.com

71. seting size of JTabpanel    coderanch.com

72. setting size    coderanch.com

Hi friends below is my program.. In my program all the controls's size are same to window size.I want to set the size by giving some size Please help..Urgent issue package com.han; import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.util.Date; import java.sql.*; public class AnnouncePopUp extends JFrame { // Class Declarations JTextField jtfText1; JButton jbnButton1; JButton jbnButton2; JTextArea jtAreaOutput; String disp1 ...

73. Java layout manager sizing    coderanch.com

import javax.swing.JFrame; import javax.swing.JButton; import java.awt.*; // The default Layout Manager for a JFrame is BorderLayout public class TestSize extends JFrame { static final long serialVersionUID = 1L; JButton aButton; TestSize(String title) { super(title); aButton = new JButton("A Button"); aButton.setMaximumSize( new Dimension(100,100) ); add(aButton,BorderLayout.CENTER); } public static void main(String[] args) { System.out.println("Starting TestSize"); JFrame theFrame = new TestSize("Testing setSize() and related"); ...

74. mig layout, jscrollpane, and min size    coderanch.com

this is my panel, which is on the bottom half of another panel (also mig layout). The trouble is this panel always end up with the panel title and the table titles are visible but not the actual data. i would like not to put the table in a scroll pane, but that appears to be how swing is designed to ...

75. Problem with locking component sizes    coderanch.com

Iam building an application that has forms with JTextFields and etc(duh). And at the moment I'am trying to lock their sizes. So they don't grow fat if window is resized. To this I'am using rightX.addComponent(phonetx,GroupLayout.PREFERRED_SIZE,GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE); in the X-axis components and BASELINE in the Y-axis ParallelGroups. But because one of my form looks like this: label I==I label label I==I I==I ...

76. Table size is coming as a full size of a frame when i used gridlayout, please Help me    coderanch.com

Don't use GridLayout here as it's not a good fit. There are many other layouts available, and I suggest that you practice using them all if you want to make your apps look better. For instance: import java.awt.*; import javax.swing.*; public class SwingFoo { private static JComboBox prptCombo; private static JTextArea ownerTextArea; public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { ...

77. Proper sizing for dynamic components    coderanch.com

Hi all, I need some help with proper component sizing. I am building a DB app in NetBeans v.6.5. I'm using the GUI designer for the most part and coding around it. Here's what I'm trying to accomplish: The user submits a school course's id. The DB is queried for the multiple choice test for that course and presents it to ...

78. preferred Size of TableColumn    coderanch.com

79. Beginner Swing - TextAerea size problem    coderanch.com

Check out setPreferredSize() Note: Not all layout managers respect the preferred size. Usually one does not set the size for the text area. Just wrap it in a JScrollPane and add the pane to the parent container. The scroll pane helps the user view/interact with the "hidden" text. Also, do yourself a favor and drop the visual editor. You end up ...

80. sizing swing components    go4expert.com

Now I am involving a java project in campus. That is using swing. We are using netbeans as ide. In my JFrame I drop a JTextArea. I have to change that's size accordingly user input. I try all the methods setMinimumSize, setPreferedSize, etc...But I coudn't see any change in width and height of jTexArea. How can i do this task? pls ...

81. JComponents Are Wrong Size    java-forums.org

I'm using a border layout. The toolbar is BorderLayout.NORTH, the left side is BorderLayout.WEST, and the right is BorderLayout.CENTER. I didn't set preferred size but I used setSize and I thought that would work. I'll try preferred size. Edit: Ok that's it. These are the things they don't tell you in tutorials :P. Thanks!

82. Defining non-Component objects with size and location using Swing    forums.oracle.com

I am attempting to write a program which will be able to manipulate (display, move, resize) objects in a Swing window which are not necessarily components. These "Window"s are defined by a Window interface which defines a Window as any object which has a size and a location (effectively a rectangular area). This would ideally allow me to perform operations such ...

83. Swing program - how to increase the size    forums.oracle.com

84. Logging Swing attributes like size and position from an external app    forums.oracle.com

Hello, I'm currently thinking about how to implement some kind of logging application which will log the JComponent properties like size, position and visibility of another running Java application. I want to do this to collect AOI (area of interest) data for eye-tracker based software evaluations. This would of course be easily accomplish-able through implementing some kind of logging directly into ...

85. Change size of my GUI    forums.oracle.com

86. GUI - Set Maximum Size    forums.oracle.com

Still posting in the wrong forum. Do you not understand the concept of actually searching a forum "BEFORE" posting a question? This question is asked and answered all the time in the Swing forum. So search there. If you don't find your answer then you post your question there so that people who actually do search the forum first can benefit ...

87. minimizing java GUI to sys tray    forums.oracle.com

I want to write an alarm scheduler GUI which will continuously run on the system, both Windows and Mac. Here are the tasks I need to accomplish: 1) When the user clicks on the close window or "X" sign, I simply want to minimize the gui to sys tray in case of Windows, or push it to background in case of ...

88. Please help with GUI problem, can't set size    forums.oracle.com

As soon as I go and resize the window or change the system font to use a different size (in fact, I did), you're hosed. You don't have full control. As I said before, I know that way can be cumbersome... I work aroud those problems you mentioned using something like a repository of constants (An abstract class, an interface, an ...