Using a JScrollPane in a JEditorPane - java

Hi so I'm struggling to apply a JScrollPanel within a JEditorPane.
I have a main content window (which has a scroll bar) and within that a JEditorPane that I would like to scroll slide horizontal and vertical. So far I have
JEditorPane monApp = new JEditorPane();
and have tried
ScrollablePanel panel = new ScrollablePanel();
panel.setScrollableWidth( ScrollablePanel.ScrollableSizeHint.FIT );
along with a few other things but couldn't seem to get any of them working.

Related

Vaadin HybridMenu shift with scrollpanel

I want to add scrollbar to my web app so I can see every components on my browser.
Red rectangle in picture below is Grid. Grid is placed inside class that extends VerticalLayout and implements View.
Green color shows my scrollbar which is added to HybridMenu instance.
HybridMenu root = HybridMenuBuilder.get()
.setContent(new VerticalLayout())
.setMenuComponent(EMenuComponents.LEFT_WITH_TOP)
.setConfig(menuConfig)
.build();
root.addStyleName("scrollpanel");
root.setSizeFull();
super.setContent(root); //class extends UI
scrollpanel definition in css:
.scrollpanel > div {
overflow: auto !important;
}
When I reduce height of browser window, menu bar is also being scrolled:
I tried to set scrollbar to VerticalLayout, but it seems like id didn't capture that grid was partly hidden. (I've setted everything in VerticalLayout to full size - How to add scrollbar to Vaadin layout)
//extends VerticalLayout implements View
private void init()
{
this.addStyleName("scrollpanel");
this.setSizeFull();
this.setMargin(false);
grid.setSizeFull();
this.addComponentsAndExpand(grid);
this.setExpandRatio(grid, 0.7f);
this.setComponentAlignment(grid, Alignment.TOP_LEFT);
}
Generally I found some not expected (at least for me) behaviour of components in VerticalLayout. They acts differently according to Layout root
(Example with VerticalLayout as root).
Questions:
How can I avoid hiding part of hybrid menu when scrolling?
Am I missing something about adding scroll panel to this VerticalLayout?
#Edit:
I found that this problem doesn't occurs if HybridMenu content is not fullSized or content is not set.
On the other hand scrollbars are not available without it.
So, creating HybridMenu the way that code below shows, solves problem with scrollpanels, but restores previous problem (layout type doesn't change anything).
AbsoluteLayout test = new AbsoluteLayout();
test.setSizeFull();
HybridMenu root = HybridMenuBuilder.get()
.setContent(test)
.setMenuComponent(EMenuComponents.LEFT_WITH_TOP)
.setConfig(menuConfig)
.build();

How to put two components at the same place

I am currently building a game and I don't know how to make a main menu. I don't know how to put the text on the GIF background. Now the thing is when I try to put them on I try this code:
private void initializeDisplay() {
playBtn.setBorderPainted(false);
playBtn.setFocusPainted(false);
playBtn.setContentAreaFilled(false);
playBtn.setText("PLAY");
playBtn.setFont(new Font("Poiret One", Font.TRUETYPE_FONT, 27));
playBtn.setForeground(Color.WHITE);
mainPanel.add(playBtn);
mainPanel.add(bgImg);
mainPanel.setLayout(new GridBagLayout());
bgImg.setLocation(new Point(200, 200));
mainPanel.setOpaque(true);
mainPanel.addKeyListener(new Keyboard());
mainPanel.addMouseListener(new Mouse());
mainPanel.setFocusable(true);
}
Also when I do that I use a GridBagLayout for the layout type but it seems that I'm not get the result I want, the problem is the button not the image in the background because that's appearing but the button isn't appearing.
You could also add an image to a jlabel's icon field, and then add the label to your panel's content pane.
This post explains it more:
How to set a background picture in JPanel

JavaFx Button adds ellipsis when rendered on a E4 ToolControl

I've an E4 application which has a ToolControl, the class that handles the tool control creates a JavaFX button, for some reason the button adds ellipsis and I've no clue why.
Here is the link to the sample application
https://github.com/SDSethia/ColoredButton.git
JavaFX shortens the label automatically, when the size of the control (a button in your case) is too small for the text. This is independent of E4. So if you increase the size of the button, the complete text will show.
I looked at your project and I am wondering why you are using the SWT renderers, although you want to use JavaFX!
If you want to use E4 + JavaFX I recommend to use the e(fx)clipse renderers. This tutorial should get you started: https://wiki.eclipse.org/Efxclipse/Tutorials/Tutorial4
The button needs a layout (I wrapped mine in an HBox) for it to render correctly. Here is the modified code
final FXCanvas canvas = new FXCanvas(parent, SWT.NONE);
button = new Button();
button.setText("FxButton (1)");
button.setStyle("-fx-background-color: #186dee; -fx-text-fill: white;");
final HBox box = new HBox();
box.getChildren().add(button);
final Scene scene = new Scene(box);
canvas.setScene(scene);
This solved the issue.

How to show scroll bar in the text area in eclipse

I am learning Java.I just created an application (liked desktop one in c#) by adding some labels,a text view and a button.
Its fun learning this new thing,but i soon encountered an issue ,when u tried to add vertical scrolling to the text view i added on the UI.
I also tried adding vertical scroll to the text area but still my text area is not displaying the scroll bar.
The part of the code created when i added the controls from the panel to the UI is as below:
thisLayout.setVerticalGroup(thisLayout.createSequentialGroup()
.addContainerGap(17, 17)
.addComponent(getJtxtArea(), GroupLayout.PREFERRED_SIZE, 158, GroupLayout.PREFERRED_SIZE)
The code for the function getJtxtArea() is as below:
private JTextArea getJtxtArea() {
if(jtxtArea == null) {
jtxtArea = new JTextArea();
jtxtArea.setBackground(new java.awt.Color(255,255,255));
jtxtArea.setFont(new java.awt.Font("Segoe UI",3,14));
jtxtArea.setWrapStyleWord(true);
jtxtArea.setLineWrap(true);
JScrollPane scroll = new JScrollPane(jtxtArea);
scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
}
return jtxtArea;
}
Can anyone tell me why i am not getting the scroll bar on the text view.Thanks in advance.
Note:I am using Eclipse Helios as the IDE and using Jigloo plugin in eclipse for the GUI.
Add the component scroll instead of the jtxtArea. In addition to that, you might also want to resize your JScrollPane.

GWT vertical menu

I need some help with Google web toolkit to make a vertical menu with expanding submenu items.
I want to create a vertical menu that woks like the left menu on the showcase of GWT
I tried this:
VerticalPanel vertpanel = new VerticalPanel();
MenuBar menubar = new MenuBar(true);//set to true so its set to vertical alignment
MenuBar subbar = new MenuBar(true);
MenuBar subbar2 = new MenuBar(true);
subbar.addItem("Fist item of submenu1", new AddEmployeeCommand());
subbar.addItem("Second item of submenu1", new AddEmployeeCommand());
subbar2.addItem("First item of submenu2", new AddEmployeeCommand());
subbar2.addItem("Second item of submenu2", new AddEmployeeCommand());
menubar.addItem("sub 1", subbar);
menubar.addItem("sub 2", subbar2);
vertpanel.add(menubar);
RootPanel.get().add(menubar);
But that doesn't work because the menu items won't expand to show their subitems. Although it works when I make it a horizontal menubar but that's not what I want.
You'll need to use DisclosurePanels in order to achieve that.
Check it out in the GWT showcase.
That's probably using a DosclosurePanel, not a Menu Bar.
http://gwt.google.com/samples/Showcase/Showcase.html#!CwDisclosurePanel
maybe you can have a look to a StackPanel
Gwt Stackpanel showcase

Categories

Resources