how to assign Richfaces Panel Bar with image as label - java

I am having a set of panelbar Items which need to have a image as label and this image will change when onexpand and shrunck of the panel .
please help me in resolving this issue

I don't see any such options from here, But you can always play with raw HTML and set image there.

First, define two CSS classes: one for the normal state (I call it panelBarClosed), the second one for the opened state (panelBarOpened), and set the image as the background:
.panelBarClosed {
background: url('/path/to/images/closed.png');
}
.panelBarOpened {
background: url('/path/to/images/opened.png');
}
Now, on your <rich:panelBarItem>, set the first class:
<rich:panelBarItem headerClass="panelBarClosed" headerClassActive="panelBarOpened">
...
</rich:panelBarItem>
I am not sure if this is enough or not (I am not able to test it right now).
If this still is not working, this component provides two other attributes that can be useful in your case: onenter and onleave. The first event is fired when you "enter" the panel bar item (i.e. you open it), the second one when you leave it. So the idea is to change the CSS class of the component on this events:
<rich:panelBarItem ...
onenter="jQuery(this).removeClass('panelBarClosed').addClass('panelBarOpened');"
onleave="jQuery(this).removeClass('panelBarOpened').addClass('panelBarClosed');">
...
</rich:panelBarItem>
(again, I didn't test it, so maybe this solution should be corrected a little)

Related

Java Swing How can I create a Color Swatch in my custom ColorChooserPanel?

I'm working on my custom ColorChooserPanel class, but I don't know how to create a ColorSwatch.
I found a class named ColorSwatch or something like that but its package private and I can't access it.
How can I ensure that I have a proper color chooser?
First, you need to think about the way this should work, to formulate your goals into action points that you can always check and see whether and how they are fulfilled:
it should be displayed
it should handle click events
it should be able to return a color (the last chosen color, or a default in lack of that)
Now, a very common way of supporting color choosers is to have something like in this image:
However, this is way too complex for a first implementation. You should first have something which "works", that is, you are able to choose colors to taste success and then work out the subsequent details. Unless you say otherwise, I'm assuming that the Basic colors section is good for now. In that case, you can create a class, which contains a JPanel, containing clickable elements. Your class needs to have a Color member, which one can get calling a getter and which is set when a clickable item inside your JPanel is clicked. The clickable items can be JPanels on their own, for example.
If you prefer something ready-made, then kindly read these:
https://docs.oracle.com/javase/tutorial/uiswing/components/colorchooser.html
https://coderanch.com/t/332515/java/Color-Palette

JavaFX switch scenes / screens / app in main BorderPane

Here is the problem,
I have a JavaFX application, main display element is a BorderPane.
I use the top of the BorderPane to display buttons, that will act like "navigation" buttons, and the center to display the current chosen application part.
Some solution, described on this link should do the trick :
https://community.oracle.com/thread/2598756
I'm really confused about the code, The only thing I really understand here is that it sets up some kind of changeListener on a list, supposed to hold the "selectedView".
Once the list changes, it triggers a function in the main part of the application, and this fuction SHOULD set the center element display with a new fxml file loaded.
So, I tried to implement quite the same example, only with 2 levels (main -> center) and get nothing working.
Here are the current files I created :
ScreenSwitcher.java
// Main class, loads the "main" fxml component
Main.fxml
// Main fxml component, BorderPane (buttons + center -empty-)
MainController.java
// Main controller, the magic should happen here
PaneOne.fxml & PaneTwo.fxml
// Children fxml, should only be displayed in the main->center element
PanelOneController.java & PaneTwoController.java
// Corresponding controllers
ViewControllerInterface.java
// An interface, as described in the given link explanation
https://github.com/Julo0sS/ScreenSwitcher
First, at app starting, I get this warning :
WARNING: Exception while evaluating select-binding [selectedView]
Then, when clicking on a button to switch the main display, nothing happens... I do have the console showing "CALL TO GOPANEWO" (or GOPANEONE), so it goes into the function code, but seems like the "changeListener" does not work...
Maybe I'm just wrong in the code, maybe there's a better/faster way to achieve what I'm trying, but actually, I'm just stuck on this...
Thanks for reading / help
Update One
Can get a part of the app working now,
The change currentView "event" is sent, and works correctly, WHEN sent by the child view itself (by click on a button in PaneOne, or PaneTwo), but does NOT work when triggered in the main view (in the top part of the borderpane, which is supposed to be a navbar)
Git repo updated with latest modifications...

Swing - Changing the content of a panel using UpdateUI

I am going through a legacy application which is using Swing and i am struggling to figure out how the screens are changing when a user clicks a button. One of the reasons i cant figure this out is because this is the first time i am using Swing. I have read a book and got the basics but still struggling.
Basically, the screen i am looking at has a JSplitPane which has a number of shortcut buttons on the left and an empty pane on the right. When i click on the button, the right side pane is populated with a different screen depending on the button pressed.
Going through the code, i was expecting somewhere that there will be something that calls a setVisible() method depending on which button is pressed.
The actionPerformed method for each of the shortcut buttons looks something like this:
void shortCutBtn_actionPerformed(ActionEvent e) {
propertyChangeListeners.firePropertyChange("selectedShortCut", previousShortCutSel, currentShortCutSel);
mainPanel.updateUI();
}
I have gone through most of the code and came to a conclusion that the above code is what is causing the frame switching but i dont understand how that is happening.
Each screen is identified by a numeric constant. In the above code example, previousShortCutSel and previousShortCutSel refer to a numeric value that represents individual screens screen.
I have tried to look for documentation of how updateUI() works but i am lost. How does the above cause the content of the right panel of the JSplitPanel to be updated with a new screen?
This is not an appropriate use of updateUI(), which "Resets the UI property to a value from the current look and feel." As the example itself may be unreliable, consider studying another. GoogleOlympiad, for example, sets a label's icon using a (cached) image.
ImageIcon image = getImage(index);
imageLabel.setIcon(image);
(source: drjohnbmatthews at sites.google.com)
As per comments by ziggy (glad it helped)
Have a look at the PropertyChangeListeners that appear to be added in the code. In particular the propertyChange(PropertyChangeEvent e) method is where the code which changes the content will be present.
+1 to trashgod nice example/advice as always

Is it possible to remove the little dropdown arrow in a JInternalFrame?

I'm using a JInternalFrame and I want to remove the dropdown in the upper left of the frame, as it serves no purpose (I've disabled resizeable, closable, etc.)
I don't see a property for this, and I don't want to remove the entire title bar, as the title is necessary. I've looked around online, and basically come up empty here. I'm hoping it's something simple that I've just overlooked, as this is my first time using JInternalFrame, and I'm not exactly a GUI kind of guy to begin with.
internalframe.setFrameIcon(null);
Edit: hack to remove system menu in Windows:
BasicInternalFrameUI ui = (BasicInternalFrameUI)internalFrame.getUI();
Container north = (Container)ui.getNorthPane();
north.remove(0);
north.validate();
north.repaint();
The relevant Icon in The Synth Look and Feel, among the Nimbus Defaults, appears to have this key:
InternalFrame:InternalFrameTitlePane:"InternalFrameTitlePane.menuButton".icon
You may be able to use the approach shown in A Synth Example to replace the Icon.
setFrameIcon(anyBigImageThatCantBeDisplayed);
I´ve tried null parameter and got some visual issues...
So i added a big image(no background) that was already on my resource folder and the icon was no longer displayed as the menu...

How to refresh the lwuit form?

I am working in a project in which user fills a questionnaire and the answers are then submitted to the server. For simplicity I have just kept two questions per screen and after clicking on the next command the user gets next two questions. I have used lwuit framework in this project.
To reduce the memory requirements I create form, questLabel1, ansCombo1,questLabel2 and ansCombo2 only once. and their properties are set as per the current frame (screen). The problem is if you are in form 2 and you scroll down to the last option and then you click the next button, since you scrolled down the form doesn't displays the upper components even on the next form tried so many thing. creating a new instance of the form may work but I don't want to use that, for obvious memory reasons,
Any other solution?
thanks in advance,
To make it scroll so that component is visible, check Component/Container API javadocs. I've seen at lwuit page these suggest some methods with semantics that fits - scrollComponentToVisible, scrollRectToVisible. "Makes sure the component is visible in the scroll if this container is scrollable..." stuff like that
// above extracted from comment to an answer to make it more visible
// for the case if some reader has similar problem
Have you tried form.revalidate()?. Because this is useful when you modify the container hierarchy and need to redo the layout.
Update: Use requestFocus(); on first component of next form. Its automatically focused on first (Upper) component.
You can use form.refreshTheme() or form.revalidate() for refreshing your form. If you have made updates on any particular container then do the same for container as well.

Categories