We want to be able to select the text on some labels.
At the moment, we're using a hack where we extend JEditorPane and then try to style it to look identical to a JLabel. This seems to work fine, but really it just lulls you into a false sense of security until a user using a screen reader asks you why you're inserting an editor which is never editable. Which, funnily enough, is exactly what has happened.
As it turns out, getAccessibleContext() for an editor pane returns the context for an editor pane, unsurprisingly. I know I can override that method and reimplement the entirety of JLabel.AccessibleJLabel myself, but there are a lot of things to implement, and I feel like there must be a better way.
Is there, in fact, a better way? e.g., it seems like I should be able to do it via the Look & Feel, but maybe there is an even easier trick.
I guess ideally, I would have hoped that there were just a property on JLabel to allow making the text selectable directly, allowing us to both keep the semantics/accessibility of adding a label to the view, while also allowing us to keep the usability.
Related
As I'm modifying an existing Look and Feel, I also want to change how the "buttons" of a PopUpMenu behave. Right now it behaves like this, when I hover my mouse over it. As you can see it behaves very "3D":
And I want to let it behave like the buttons I made below them:
I've looked trough alot of documentation of Java Swing but I can't seem to find it. So if someone knows, please help me out. I have tried to change every property I could find.
The correct answer here is, as I found out, not everything can be managed by the LaF. Therefore, sometimes you have to get your hands dirty.
In this case I created my own CSTMButton, because in Swing one is also able to add buttons to a menubar. Now I can create it's own listener to generate the behaviour I want.
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).
I thought it would be nice if I gave the user the ability to choose and switch between "themes" (L&Fs). I'd give him a choice between Java metal (default), System default, and maybe a couple more I'll download from the internet...
My application is also bilingual (you can pick between two languaes to be displayed).
However, it's important for my application to be fully translated. I can handle the simple stuff, naming JLabels, JButtons, titles of frames, etc...
But there are also some predefined components whoose string I cannot manage as easely (e.g. JFileChooser). I was told that I could change them using the UIManager, but that their strings are L&F specific.
Now, regardless to how much fun would be translating my application for each and every L&F, I hope there is some centralised way of controlling those strings.
After all, JFileChoose (e.g.) is the same component, no matter the L&F that is used, right?
It prints text on the same parts of itself, no?
So, there should be something I could access that would grant me "master" control over the text that is printed onto the predefined components, I assume...
Any ideas?
not easy job,
have to read Modifying the Look and Feel
most important is Changing the Look and Feel After Startup
have to accept that you have to override value for Keys into UIManeger too, NOTICE about one of Look and Feel
is possible that different L&F have got various Fonts and Colors for concrete JComponents, multiply by Native OS
in some cases is important if you'll to change Color or ColorUIResources (Font or FontUIResources)
JFileChooser is compound JComponents, you can to extract its members,
best place to start could be this idea,
Nimbus Look and Feel lives with own life
I have a fairly complicated JTable subclass (WidgetTable and its WidgetTableModel) that works fine when I add it to a dummy JPanel for testing purposes.
Since I am absolutely horrid at working with LayoutManagers, I like to use the NetBeans built-in GUI Builder for all my layout work. Then I usually just code-around the autogenerated (GUI builder) code and that has always worked for me. It is the best of both worlds: I get my presentation looking exactly the way I want it, and I also get fine-grained control over the componentry.
However, I have never used the GUI Builder tool to make tables. After tinkering around with it for a while last night, it looks as though it is only good for making pretty basic (fixed # of rows, fixed # of columns, etc.) JTables.
My WidgetTable actually has a dynamic number of both rows and columns, special editors/renderers and many other bells and whistles.
My problem:
I have two conflicting constraints: (1) I need to use the GUI builder to position and size the table exactly where I want it in the container, but, (2) The table component available through the GUI builder is too basic to handle my WidgetTable.
I need a way to design a "table placeholder" into my container with the GUI builder, such that, once NetBeans autogenerates that placeholder code, I tweak the code and instruct it to dynamically instantiate one of my WidgetTables instead, consuming the location and size that I defined the placeholder component to take up.
This way I can have my cake, and eat it too. The only problem is, I don't think the GUI builder supports this ability to drag-n-drop abstract JComponents, position and size them, and then plug subclasses into them elsewhere in the codebase.
Anybody ever have this problem before or have any interesting recommendations? I imagine the best thing to do would be for me to just roll up my sleeves and learn LayoutManagers, but I'm mostly a server-side developer and only come over to the client-side every once in a blue moon; and honestly, don't have the energy to learn the intricacies and nastiness of GroupLayout and its sinister cousins.
Thanks for any help!
Insert a JTable using the GUI builder, reset its model property to the default value, and tweak the construction code so that it looks like
jTable1 = new WidgetTable(this.widgetTableModel);
You may tweak the creation code by right-clicking on the JTable, selecting "Customize code", choosing "custom creation" instead of "default code" in the first combo box, and typing the code for the constructor call.
If you need your jTable1 variable to be of type WidgetTable rather than JTable, edit the "Variable declaration code" in the same dialog box.
NetBeans also allows you to create custom components for building UIs. This may be more work than you want to put into your WidgetTable, but if you think you're going to have to build more UIs with custom components, it could be worth learning.
I do this all the time. I have an subclassed JTable that I use with the GUI editor and it is Dynamic.
Add a JTable to your project using the GUI editor and the layout of your choice.
Once the table is added, right click on it and click on custom code.
In the constructor of the JTable, change it to say new WidgetTable(new WidgetModel()) instead of new JTable(new DefaultTableModel()).
Create a global variable for you WidgetTable. Something like private WidgetTable widgetTable;
In you constructor, after the call to initComponents(), cast your JTable to a Widget table and use that from now on.
`widgetTable = (WidgetTable)jTable1;
Below UI is something I'd like to aim for. But I have no idea, how they have the "skin" of the app. On my end, the Java application looks like it was made in 1990s. I want to change a look to a more modern style.
What components are they using possibly here? JSplitpane for one. but I'm not sure how they created that "Dokument/Vorschau" tabs.
First using a look and feel like Nimbus, can easily change the look of your application to a have a more modern feel.
Second, you will need to customize the font, color, borders, node icons, etc. of each component type to achieve a non-standard look. Some of these can be changed with updates to the UIDefaults of the look and feel but many will be made by calling methods on the specific instance of the component you are dealing with.
Try a javax.swing.JTabbedPane.
If you really want to change the complete look-and-feel of your application from scratch, you should take a look at Synth L'n'F. You can define style and appearance of components and bind them to components which match certain criteria.
(My opinion on that matter: heavily themed apps usually look and feel out-of-the-place and only make it harder to use the app, so I'd actually try to avoid themeing)