I have an application that uses Swing. The display I am working on, uses a Box with a Horizontal Layout as the top container. In it, are three other boxes (which actually contain the content). The appearance to the user is a window with three panes, arranged horizontally across the screen. What I want to do is give the user the ability to change the pane sizes (the width of the panes). I tried putting the interior boxes in a JTable, that failed miserably. Any other ideas?
Thank you
Try using a nested JSplitPane.
Related
I have written a Swing UI that has a JPanel with numerous controls and on the right hand side a few columns of JCheckBoxes. This is all handled by making the JPanel use a GridLayout. The problem I am having is that a given checkbox toggles it's selection status no matter where in it's grid "cell" you click in. Note, I am not using a JTable approach. The "cell" is just the rectangular area of the screen the GridLayout gave to the checkbox. It can be much bigger than the checkbox. I can't figure out how to make sure the checkboxes are only selectable when you click in the tiny box of the drawn control (not the big box of the "cell" that the checkbox is basically centered in). I've googled a lot and everyone talks about JTables. Again, I am not using a JTable. This issue is causing headaches for my users as they click on the application window and accidentally select an option!
The GridLayout forces all UI components to fill their cell completely, so the actual checkbox only gives the illusion that it's smaller than the cell it occupies. The solution here, as with many other more complex UI designs, is to use multiple layouts nested inside one another.
In your case, try putting all your check boxes inside a BoxLayout and using glue to space them as needed. This BoxLayout should be placed side by side with your GridLayout in another enclosing container (either a JPanel or your ContentPane -- I can't say for sure because you only gave a brief description of your UI with no code or illustration).
Play around with the idea of nesting layouts until you get something you like, and don't forget to try resizing your window to see what the layout manager does under the circumstances. The final appearance isn't always exactly what you imagine it will be.
Problem is when i create GUI in jFrame window on screen and run the program later it in full screen using
setExtendedState(MAXIMIZED_BOTH);
it do not show up like it looked in that window see the red bordered area
Components appears in one corner of screen or only at a small part in center depending upon layouts and rest is empty space like this
I want JFrame window (see the red bordered area in first image) which is showed while creating GUI to represent my whole screen so that i can know how it will look when i run it in full screen.
Change the layout manager, may be using a combination of BorderLayout and GridBagLayout
These will provide you with a means to define how the components are positioned and sized within the parent container
See Layout out components within a container for more details
I'm designing GUI using java swing with the help of windowbuilder. I found that in any layout it's not possible to resize components by using mouse drags (even though it shows points to pick and drag to resize). Specifically reducing size is what most important to do.
Resizing is allowed only in two layouts: one in Absolute Layout (which is not at all good for practical purpose, considering different screen-sizes with which GUI should be better displayed) and another is Group Layout (which is also not a good for design due to it's complex code).
Following is the sample where I have placed two JLabels and now trying to add JComboBox at the location indicated by Green box.
But when I place the JComboBox it's default size is to fill horizontally. Even if I change fill to 'None' and try to resize, I'm unable to resize it. Following is the result after addition of JComboBox:
In the Background there is JPanel with GridBagLayout with following properties:
I found that changing values in columnWidths and rowHeights properties of GridBagLayout, the size of grid columns/rows can be controlled. But I'm unable to understand Size of which columns/rows all those values represents?. (I found no direct relation between number of those values and number of columns/rows displayed on Panel)
Is there any way out to resize components? And can anybody explain what those values in columnWidths and rowHeights properties of GridBagLayout represent?
It's simple, you need to add grow in you WindowBuilder. It looks like this:
picture
Click on this with your right mouse button and click on 'grow':
picture
Only objects with 'grow' are resizable.
I want to make an account screen for a project, but I'm still new to GUI's. This is my first time working with a JComboBox and I'm having a bit of trouble. I want to basically place the JComboBox inside a box, which will be part of my background image. I tried using BorderLayout, but that just made a giant combobox that took up my entire screen. I have my code here and a drawing which illustrates my goal below:
See this answer for 2 layouts that can easily center the panel containing the combo box.
Use borders and layout padding within that panel for the white space required.
My Java GUI app contains a scrollable text window. Besides a standard scrollbar, I need a vertical bar with colored line markers, like in Eclipse. Hopefully you know what am I speaking about. This bar is not scrollable, markers positions are arranged proportionally to the height of the whole text. When user clicks on any marker, text box scrolls to the corresponding line.
I were not able to find such control in SWT widget suites. Obviously SWT contains it somewhere. The ideal option for me would be Swing component because application is Swing-based.
Many thanks in advance.
I don't think there is a component bundled with Swing and I don't know of any library supplying such a component, bu you should be able to do it yourself.
Provide a panel next to the scrollpane and whenever the scrollpane/textpane are rerendered rerender that panel, too. Then place markers (could be JLabels in a first step, later draw your own and add mouse handling) according to the lines - the layout manager should be null in this case.
The position could be calculated by using line/numlines * height(panel), e.g. for line 20 of 100 and a panel height of 200, the position of the marker would be at height 20/100 * 200 pixels = 40 pixels.
The ruler you want is not from SWT. Its from the jface-text plugin. The class you are looking for is org.eclipse.jface.text.source.CompositeRuler
In case you are still asking, here is a (not-free) marker bar component:
http://www.sideofsoftware.com/marker_bar.htm