jOptionPane dont show on top windows. Java 1.4 - java

jOptionPane dont show on top windows.
I've read that using
JFrame frmOpt = new JFrame();
frmOpt.setVisible(true);
frmOpt.setLocation(100, 100);
frmOpt.setAlwaysOnTop(true);
should be enough, but the problems is that I'm using Java 1.4 and 'setAlwaysOnTop' does not exists.
so....is there a way to solve this situation?
thanks in advance.
EDIT: Here is what I'm doing:
JFrame frmOpt = new JFrame();
frmOpt.setVisible(false);
response = JOptionPane.showOptionDialog(frmOpt,message,mens, 0,JOptionPane.OK_CANCEL_OPTION,null,options,null);
First I create a JFrame, then I create a new JOptionFrame setting the JFrame.
And it still shows at the back. Notice I do not use setAlwaysOnTop because of Java 1.4

Related

eclipse ide java not loading jpanels

so my problem is quite bizarre. So I am trying to write a java program in the eclipse ide. I have one JFrame and multiple JPanels added to it. You can navigate through the JPanels via buttons setting one panel to not be visible and another to be visible, you get the idea. However, after some time this started to occur: when I press a button the correct JPanel is being set to visible and I can see it, but it is completely empty. Sometimes its content is displayed correctly, but this is rather inconsistent.
As I said: sometimes this happens, sometimes it doesnt happen. I would start the program and close it 5 times and the 6th time it finally works. I don't think the code is necessary (as it is all correct because, after all, it does work sometimes), but if you want to see it feel free to ask. My eclipse workspace is on my C drive on an SSD and it is not too full. it has like 100 out of 250 gigs left. Thank you for your time and help in advance!
Edit:
So heres the code example.
Two of the JPanels Im trying to switch between:
The "main" panel
Var.menuPanel = new JPanel();
Var.jf1.add(Var.menuPanel);
Var.menuPanel.setBounds(0, 0, Var.screenwidth, Var.screenheight);
Var.menuPanel.setLayout(null);
Var.menuPanel.setVisible(true);
Var.menuPanel.revalidate();
Var.menuPanel.repaint();
This loads all fine.
The button to switch to the other panel:
Var.editCourse = new JButton("Edit");
Var.menuPanel.add(Var.editCourse);
Var.editCourse.setBounds(550, 120, 200, 50);
Var.editCourse.setVisible(true);
Var.editCourse.addActionListener(handler);
Var.editCourse.setBackground(Color.YELLOW);
The other JPanel + UI elements
Var.editCoursePanel = new JPanel();
Var.jf1.add(Var.editCoursePanel);
Var.editCoursePanel.setBounds(0, 0, Var.screenwidth, Var.screenheight);
Var.editCoursePanel.setLayout(null);
Var.editCoursePanel.setVisible(false);
Var.editCoursePanel.revalidate();
Var.editCoursePanel.repaint();
Var.editCourseToMenu = new JButton("Back");
Var.editCoursePanel.add(Var.editCourseToMenu);
Var.editCourseToMenu.setVisible(true);
Var.editCourseToMenu.setBounds(550, 400, 200, 50);
Var.editCourseToMenu.addActionListener(handler);
Var.editCourseSelection = new JComboBox<String>(JSONHandler.courses);
Var.editCoursePanel.add(Var.editCourseSelection);
Var.editCourseSelection.setBounds(550, 200, 200, 50);
Var.editCourseSelection.setVisible(true);
Methods.setArrowBounds(Var.editCourseSelection);
Var.editCourseSelection.setSelectedItem("Edit.");
Var.submitCourse = new JButton("Continue");
Var.editCoursePanel.add(Var.submitCourse);
Var.submitCourse.setBounds(550, 300, 200, 50);
Var.submitCourse.setVisible(true);
Var.submitCourse.addActionListener(handler);
The line in the AcionHandler:
else if(e.getSource() == Var.editCourse) {
MenuHandler.showEditCoursePanel();
}
The showEditCoursePanel methtod:
public static void showEditCoursePanel() {
Var.menuPanel.setVisible(false);
Var.editCoursePanel.setVisible(true);
}
Oh and also, sometimes when it doesnt load, there is the scrollbar of a JScrollPane on the side, which, as you can see, is never even mentioned.
Edit 2:
Okay, I found the source of the problem. When I add the raw JPanel to the JFrame and workt with that it all works fine, I cant scroll of course. But when I add the JScrollPane the newCoursePanel doesnt show up at all. Everything else is now working fluently, except for the panel with the scrollbar. Heres the code form the nwCoursePanel im talking about:
Var.newCoursePanel = new JPanel();
Var.newCoursePanel.setBounds(0, 0, Var.screenwidth, Var.screenheight);
Var.newCoursePanel.setLayout(null);
Var.newCoursePanel.revalidate();
Var.newCoursePanel.repaint();
Var.newCoursePane = new JScrollPane(Var.newCoursePanel);
Var.newCoursePane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
Var.newCoursePane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
Var.newCoursePane.setVisible(false);
Var.jf1.add(Var.newCoursePane);
I cant figure out how to get it working though. in to show the panel I just Var.menuPanel.setVisible(false) and Var.newCoursePane.setVisible(true).

Set the size of Vaadin GridLayout as the ScreenSize in java

i'm using Vaadin GridLayout in a project, and i want to make it big as the screen so i can arrange the UI of the app.
i'm a beginner in java, i tried .setWidth("100%"); , and also tried
to get the Screen resolution with Toolkit, but it did'nt help.
i've already searched around but none could've helping me.
can anyone give me a hint?
here is a part of it:
filter.setWidth("100%"); //TextField
entryList.setWidth("100%"); //Table
entryList.setHeight("100%");
blayout.addComponents(addNew,delete); //HorizontalLayout
blayout.setStyleName("buttons");
Styles style=Page.getCurrent().getStyles();
style.add(".buttons {float:right;}");
layout1.setMargin(true); //VerticalLayout
layout1.setSpacing(true);
layout1.addComponents(filter,entryList,blayout);
layout1.setWidth("100%");
layout1.setHeight("100%");
layout1.setSizeFull();
layout2.setSizeFull(); //VerticalLayout
layout2.addComponent(form); // form is a variable of an other class
layout2.setWidth("100%");
layout2.setHeight("100%");
MPanel panel1=new MPanel("Search");
MPanel panel2=new MPanel("Edit");
panel1.setSizeFull();
panel2.setSizeFull();
panel1.setContent(layout1);
panel2.setContent(layout2);
panel1.setWidth("100%");
panel1.setHeight("100%");
panel2.setWidth("100%");
panel2.setHeight("100%");
mlayout.setRows(1); //GridLayout
mlayout.setColumns(2);
mlayout.addComponent(panel1,0,0);
mlayout.addComponent(panel2,1,0);
mlayout.setSpacing(true);
addComponents(new MVerticalLayout(menue, mlayout)); //Creates Output

Charset in JTextPane which using AdvancedRTFEditorKit

I'm having some problems with charset encodings. I'm using AdvancedRTFEditorKit (free closed source library: http://java-sl.com/advanced_rtf_editor_kit.html).
If I copy some special characters (ěščřžýáíé) from MS Word and paste them into sample delivered with AdvancedRtfEditorKit library, everything works fine. But if I do the same with my really simple SSCCE which uses AdvancedRTFEditorKit, then they appear as just rectangles. Do you know what I'm doing wrong?
This problem only occurs with MS Office products. LibreOffice works fine.
My SSCCE:
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setSize(350, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JTextPane pane = new JTextPane();
pane.setEditorKit(new AdvancedRTFEditorKit());
frame.add(pane);
frame.setVisible(true);
}
After many changes in my code I figured out there isn't any problem with my app. My problem was just running app directly from NetBeans IDE. I don't know why, but IDE somehow encode/decode interaction with OS.

Making a custom icon for a JFrame

Well I was wondering if I could make an icon image for a JFrame. I do know its posible, because, let me say, I am NOT digging the java logo.
Well if I just hava to use a Frame object I will.
Can someone tell me, I know its possible!
Use an ImageIcon.
ImageIcon icon = new ImageIcon( pathToIcon );
yourFrame.setIconImage(icon.getImage());
Good Luck!
First, you have to have an image file on your computer. It can be named anything. For this example, we will call this one "pic.jpg".
Next, you need to include it in the files that your application is using. For example, if you're using NetBeans, you simply click on "Files" in the left hand side of the IDE (not File as in the menu, mind you). Drag the picture's file over to the folder that houses the main package. This will include it for available use in the code.
Inside the method where you define the JFrame, you can create an image like this:
Image frameImage = new ImageIcon("pic.jpg").getImage();
You can now set it as the IconImage for the frame like this:
JFrame frame = new JFrame("Title");
frame.setIconImage(frameImage);
Hope that's helpful.
Note: the reason that the Image object has to be created like this is because Image is abstract and cannot be instantiated by saying new Image();
Props to you, btw, kid. I wish I would have started learning programming when I was your age. Keep at it!
You can do the following.
public Test {
public static void main(String[] args) {
JFrame frame = new JFrame("My Frame");
frame.setIconImage(new ImageIcon(Test.class.getResource("image.png"));
frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
frame.setVisible(true);
frame.setSize(100, 100);
//other stuffs....
}
}

Minimizing the application in windows problem

I've wrote a simple application to store some text in a derby DB. I have 2 button each one creating a new inputDialog. My problem is that when I run the program on my Ubuntu PC all is well. When I run it on a windows 7 PC when the input dialog is displayed the whole thing is minimized and hidden from the user. So each time I want some input from the user he has to restore the application. And the other problem is that the program doesn't appear in the alt-tab menu too. Here is the code that I use to display the dialog:
String s = (String) JOptionPane.showInputDialog(this, "Моля въведете име:");
All help will be greatly appreciated.
I tried the following code - directly from main() via eclipse running on Windows 7 64-bit. The JFrame remains on display, even if I try otherwise.
JFrame f = new JFrame();
f.setSize(750, 500);
f.show();
JOptionPane.showInputDialog(f, "hello", "there");
System.out.println("hi");
Try this, and if you get the same result then at least we know it's a windows issue that we're dealing with rather than a Java issue.
EDIT:
After looking through your code, I found the offending line. Also as a side note, you should generally call setVisible() after you have done configuring your window. This is especially true with my code, as it would throw an exception if you try to call setUndecorated() after you have displayed the window.
Your Code:
this.setVisible(true); //This should be called after you finish configuration
device.setFullScreenWindow(this); //This is the problem!!!
Instead you should use:
this.setExtendedState(JFrame.MAXIMIZED_BOTH);
this.setVisible(true);
If you want to have your window fullscreen then use:
this.setUndecorated(true);
this.setExtendedState(JFrame.MAXIMIZED_BOTH);
this.setVisible(true);

Categories

Resources