float checkboxes on expand in Swing - java

I've made a simple GUI with 2 lines of checkboxes. The checkboxes are all the same size. When I maximize the application, they are anchored on the left so it looks a bit out of place.
I would like to have the checkboxes slowly move to the first line if there is space. Similar to the way 'float' works in CSS (on websites).
Does Swing have this type of functionality?

Check out Wrap Layout which works in many cases.

Similar to the way 'float' works in CSS (on websites).
Look to FlowLayout for that effect.

Related

How can I prevent JTextPane to grow horizontally...?

I am building an application with several tabs containing JPanels with JTextPanes. While testing, I wrote text longer than the screen, and the JTextPane grows horizontally. Does somebody know a way to stop it from growing like that? Also, how can I force that the text, once the line has been completed, jumps to the next line on the JTextPane?
Thanks!
UPDATE: I opted for the first option that Julien Gauthier mentioned, which is using JTextArea and enabling the Wrapping. It worked neatly. Given that the size of my text boxes (or areas) is more than enough for the limit I established as text capture (800 characters), I did not need to add Scrolls to the text areas. And also, I did not had any trouble with my save-text-to-file functions with JTextAreas instead of JTextPanes. Thanks a lot for the help!
I wrote text longer than the screen, and the JTextPane grows horizontally. Does somebody know a way to stop it from growing like that?
Add the text pane to a JScrollPane and then add the scroll pane to the frame. Then the text will wrap and scrollbars will appear when required.
Read the section from the Swing tutorial on Text Component Features for a working example of a text pane.
You have several possibilities :
You can first replace the JTextpane by a JTextArea, and use jTextArea.setLineWrap(boolea wrap).
You can use an editorKit with your JTextPane, wich will wrap the text. Please look this example : http://java-sl.com/tip_html_letter_wrap.html
You can use a JScrollPane, but the result will be ugly with long sentences.
Good luck.

GWT vertical align labels and textboxes in java code

I am trying to vertically align a label and 2 text boxes. I tried to use a horizontal panel, a grid and a flex table, but none of them seems to perfectly align the text. Do you have any suggestions?
You can use .setVerticalAlignment(HasVerticalAlignment.TOP); in HorizontalPanel, but according to the documentation this property affects only widgets that have been added after this property has been set.
If you only support modern browsers, a better solution is to use Flexbox layout model.
You can simply try it with Vertical panel to add widgets like label and textBox.
this can be useful to you, http://www.tutorialspoint.com/gwt/gwt_verticalpanel_widget.htm

How to edit the Scroll Bar

I have a JTable in a JScrollPane but I'd like to change the look of the ScrollBar to something a bit better looking; a 'custom design'. Maybe put an image that a user can drag instead of the default thick blue bar. Is this even possible?
The main thing I'd like to do is change the thickness of the bar. My application uses a small window and the ScrollBar looks too thick.
Any help will be much appreciated.
Edit:
Thanks for the responses so far. I just found this; answers my answer, in part: java scrollbar thickness
Unfortunately I cannot provide a sample at the current moment, but you should definitely look into this
The BasicScrollBarUI class allows you to modify different features of a typical JScrollBar, such as various different colors, sizes, and shadow effects. This should be what you are looking for. Basically the idea is that you are supposed to override the installDefaults method and just modify the protected fields to your liking.
But, if you want to get fancy, I would highly suggest looking into JavaFX due to the amount of customizability it supports, one being CSS styling (which should be very helpful to you).

Java SWING - How to put my functionality under my tabs?

At the Moment I am coding my GUI, but my programm functionality flows under my tabs.
Example:
Does anybody has an idea how to fix that?
Your Layout is broken.
Try to split up component-parts (tabs and the panel content below tabs).
Add only these parts and see whether the layout of those particular components is OK.
Put everything you have into a scrollable would help you to analyse the problem and see the actual required size of your components.
Try to avoid using prefferedSize/minSize/maxSize in your code, it was not meant to layout your stuff.

Dynamically add Textbox to Window when checkbox is checked

I'm just figuring out my way around SWT. I have a little problem that i cant seem to solve. I have a check-box in my window. When the check-box is checked, i would like add a multi-line, read-only, text box below it, lets say 200x200. I want the height of the window to increase to accommodate this text-box. When the check-box is unchecked I'd like the opposite to happen.
Could you help me with this? I can't find an example but maybe I'm not using the right keywords. Cheers.
--EDIT
the.duckman'ss answer was very helpful. I've managed to get it working to some extent. I'm adding a multi-line textbox 480px high. How do I automatically resize the window to accommodate the text box? When the user checks the checkbox, the textbox shows up but the height of the window doesn't increase to accommodate the textbox. My code is a little long so I've put it in PasteBin — http://pastebin.com/01RxKeEr
Thanks.
I recommend looking at the SWT Snippets to every beginner - that's probably the best place to go to with SWT questions.
This snippet does exactly what you want.
Edit
Ooops, I ignored the second half of your question, sorry. Simply add this line to your listener:
shell.setSize(shell.computeSize(SWT.DEFAULT, SWT.DEFAULT));

Categories

Resources