refreshing data in jscroll pane swings - java

I have a main panel in which there is another panel to which i am applying scrolling.This panel in turn contains 2 panels.
Now when i apply scrolling the scroll bar appears.
The problem is when I dynamically add data from the user screen partially.....the data appears onto the screen but I am not able to scroll it panel down and the data below the scroll bar is not seen properly.
generalInformationPanel = new JPanel(new GridLayout(1, 1));
generalInformationPanel.setBounds(0, 0, 1050, 500);
generalInformationPanel.setBackground(Color.WHITE);
gd_GeneralInformationUpperPanel = new JPanel();
gd_GeneralInformationUpperPanel.setBounds(0, 0, 1050, 700);
gd_GeneralInformationUpperPanel.setLayout(null);
gd_GeneralInformationUpperPanel.setBackground(Color.WHITE);
js1 = new JScrollPane(gd_GeneralInformationUpperPanel,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
js1.setBounds(0, 0, 950, 450);
js1.setVisible(true);
generalInformationPanel.add(js1);
add(generalInformationPanel, BorderLayout.CENTER);

Related

Add 2 JTextPane to one scrollPane

I am trying to add 2 JTextPane to one scrollPane. But it not scrolling. What am I doing wrong?
JScrollPane scrollPane = new JScrollPane();
scrollPane.setBounds(402, 211, 178, 193);
frame.getContentPane().add(scrollPane);
JPanel panel = new JPanel();
scrollPane.setViewportView(panel);
panel.setLayout(null);
JTextPane textPane_branding = new JTextPane();
textPane_branding.setBounds(98, 0, 78, 191);
panel.add(textPane_branding);
JTextPane textPane_trunk = new JTextPane();
textPane_trunk.setBounds(0, 0, 88, 191);
panel.add(textPane_trunk);
I'm not quite sure what you are trying to achieve here. If you want both of your JTextPane to be scrollable you need to put each one into its own JScrollPane. That would look like this:
JTextPane textPane_branding = new JTextPane();
JScrollPane scroll_branding = new JScrollPane(textPane_branding);
scroll_branding.setBounds(98, 0, 78, 191);
panel.add(scroll_branding);
JTextPane textPane_trunk = new JTextPane();
JScrollPane scroll_trunk = new JScrollPane(textPane_trunk);
scroll_trunk.setBounds(0, 0, 88, 191);
panel.add(scroll_trunk);
If you want both of your JTextPane being into one JPanel that is scrollable I'm wondering why you set fixed Bounds to your JScrollPane and to the JTextPanes. That makes Scrolling absurd here. And thats why JScrollPanes don't work with Panes that don't have Layouts and use fixed Bounds. Also it is very bad practise.
So I would suggest here to stay with a Layout Manager in your JPanel and use setPreferredSize with your JTextPanes to define your desired Dimensions. And then your JScrollPane will start working.
JScrollPane scrollPane = new JScrollPane();
//scrollPane.setBounds(402, 211, 178, 193); // Don't do this!
frame.getContentPane().add(scrollPane);
JPanel panel = new JPanel();
scrollPane.setViewportView(panel);
//panel.setLayout(null); // Use a Layout Manager
JTextPane textPane_branding = new JTextPane();
textPane_branding.setPreferredSize(new Dimension(78,191));
//textPane_branding.setBounds(98, 0, 78, 191);
panel.add(textPane_branding);
JTextPane textPane_trunk = new JTextPane();
textPane_trunk.setPreferredSize(new Dimension(88,191));
//textPane_trunk.setBounds(0, 0, 88, 191);
panel.add(textPane_trunk);

Swing components are too small

So I have this code in my contructor, my class extends JFrame:
super("myBucketList");
i = new Item();
//controls panel
controls = new JPanel();
itemField = new JTextField();
itemField.addActionListener(new ListenAction());
delField = new JTextField();
delField.addActionListener(new ListenAction());
listArea = new JTextArea();
listArea.setEditable(false);
controls.add(delField);
controls.add(itemField);
//txtareaPanel
textareaPanel = new JPanel();
listScroll = new JScrollPane();
listScroll.setViewportView(listArea);
textareaPanel.add(listScroll);
//tab1 panel
tab1 = new JPanel();
tab1.setLayout(new BorderLayout());
tab1.add(controls, BorderLayout.NORTH);
tab1.add(textareaPanel, BorderLayout.CENTER);
add(tab1);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(500,200);
setVisible(true);
Now if I run my application the components are really small, how to fix it?
Here is a screenshot of the situation/problem: http://snag.gy/yjbUl.jpg
Thanks
Just call the constructor with columns, see here
For example:
itemField = new JTextField(10); //Or the number of cols you want
Or call JTextField#setColumns()
itemField.setColumns(10); //Or the number of columns you want
For the JTextArea call this constructor as follows:
listArea = new JTextArea("", 10, 10); //Text, rows, cols.
Or again use JTextArea#setRows() and JTextArea#setColumns() as follows:
listArea.setColumns(10);
listArea.setRows(10);
That should fix your problem.
If you are using jdk 8 then keep it but
download the jre 9 and your widgets
etc will be of normal size. This solves the
problem!

How do i create two or more colums inside a scrollpanel in GWT?

In general a scroll panel has only one column. If I want two columns, how do I have to modify my code?
ScrollPanel scrollPanel =new ScrollPanel(panel1);
scrollPanel.setSize("200px","100px");
DecoratorPanel decoratorPanel =new DecoratorPanel();
decoratorPanel.add(scrollPanel);
RootPanel.get("gwtContainer").add(panel);
RootPanel.get("gwtContainer").add(decoratorPanel);
You can scroll a Grid, FlexTable or LayoutPanel so you will have a common scroll for a flexible layout.
LayoutPanel lp = new LayoutPanel();
lp.add(whatever1);
lp.add(whatever2);
lp.setWidgetLeftWidth(whatever1, 0, Unit.PCT, 50, Unit.PCT);
lp.setWidgetRightWidth(whatever2, 0, Unit.PCT, 50, Unit.PCT);
ScrollPanel scrollPanel = new ScrollPanel(lp);
scrollPanel.setSize("200px", "100px");
DecoratorPanel decoratorPanel = new DecoratorPanel();
decoratorPanel.add(scrollPanel);
RootPanel.get("gwtContainer").add(decoratorPanel);
Hope it helps

JTextfield in JTabbedPane oversized

textArea = new JTextArea(textString);
JScrollPane text = new JScrollPane(textArea,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
text.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
And I add the JScrollPane text to a JTabbedPane, nothing special.
However the texfield expands and resizes the entire window when I switch tabs.
JFrame frame = new JFrame();
frame.setSize(600, 500);
JPanel main = new JPanel();
main.setLayout(new BorderLayout(0,0));
main.setBorder(new EmptyBorder(10, 10, 10, 10) );
textArea = new JTextArea(textString);
JScrollPane text = new JScrollPane(textArea,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
text.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
JTabbedPane tabs = new JTabbedPane();
tabs.add("Text lines", text);
tabs.add("Another", new JPanel());
main.add(new JLabel("test"), BorderLayout.NORTH);
main.add(tabs, BorderLayout.SOUTH);
frame.setContentPane(main);
frame.pack();
The problem that I found with your example is that when you enter many lines in the text area and switch to another tab, then the tabbed pane grows in size. In order to fix that, just enter how many text area rows you want to be display in the JTextArea constructor. For example, to display 5 rows:
textArea = new JTextArea(textString, 5, 0);
Now the tabbed pane will not get resized.

a retractable JTextArea with scrollpane

Goodevening
how can have a JTextArea like in netbeans (see the pic)
(source: hostingpics.net)
my code of the JTextArea:
JTextArea infoArea = new JTextArea(10,10);
infoArea.setLineWrap(true);
infoArea.setFont(police);
infoArea.setForeground(Color.YELLOW);
infoArea.setBackground(Color.BLACK);
infoArea.setEditable(false);
JScrollPane scroll = new JScrollPane(infoArea);
scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
scroll.setBorder(BorderFactory.createEmptyBorder(5, 0, 10, 0));
scroll.setPreferredSize(new Dimension(sousFrame.getWidth(),90));
scroll.setFont( new Font("Arial", Font.BOLD, 13));
scroll.setBorder(BorderFactory.createTitledBorder("Output"));
thank you
I'm not sure what NetBeans uses, but we used flexdock at my last company to create dockable windows in a Java Swing application (assuming this is what you meant by "retractable").

Categories

Resources